The fastest way to access VB6 String in C #

I am using COM Interop. I have a call in VB6 that returns a string of approximately 13,000 characters. If I make a call in pure VB6, it takes about 800 ms to complete. If I execute it through C # and COM Interop, it will take about 8 seconds. I assume the delay is due to marshaling.

If I am right about marshaling, I would appreciate if anyone could suggest the fastest way to get this in C #. for example It would be better a) expose it as an array of bytes b) provide the byref string parameter to the VB6 level

I would appreciate a sample code. I tried

Marshal.PtrToStringAuto(Marshal.ReadIntPtr(myCOMObject.GetString, 0) 

to no avail.

-

Further from Franky's comment. I just reference the VB6 dll (so in the process) from C # dll. Here is an excerpt from OLEView

 interface _MyCOMObect : IDispatch { ... [id(0x60030006)] HRESULT GetString( [in] _IEventHistory* p_oEventHistory, [out, retval] _IXML** ); ... }; [ uuid(09A06762-5322-4DC1-90DD-321D4EFC9C3E), version(1.0), custom({17093CC6-9BD2-11CF-AA4F-304BF89C0001}, "0") ] coclass MyCOMObject { [default] interface _CFactory; }; [ odl, uuid(C6E7413F-C63A-43E4-8B67-6AEAD132F5E5), version(1.0), hidden, dual, nonextensible, oleautomation ] 

I should probably indicate that the parameter (p_oEventHistory) is another COM object that I create in C #, but it takes about 80 ms

S

+7
string c # vb6 marshalling com-interop
source share
2 answers

A few things: -

  • My VB6 is a little rusty, but your IDL snippet assumes that the GetString method actually returns an object that implements the IXML interface. I'm a bit surprised that Marshal.PtrToStringAuto can do anything useful with this. Could you change VB6 so that it really returns something like String?

  • The effect of COM + is potentially huge. First, I would suggest comparing timings for the first call and subsequent calls. COM + will need to deploy a host process for your VB6 component on the first call, so the first call will always be more painful. Note that this happens on the first call, and not in the creation of the object. Secondly, how your component is configured in COM + can also make a big difference; if you disable all COM + services that you really do not need (for example, transactions), you can remove the part of the interception logic that COM + places in all method calls. Ultimately, if you do not need the services provided by COM +, do not use it.

+2
source share

I would like to use memory mapped files or named pipes.

0
source share

All Articles