views:

181

answers:

1

Hi! I have this problem, which I am dealing with for some time already. At start, I have two dlls with unmanaged code (let's say... dll_1, dll_2) and managed aplication in c#. What i'm supposed to do is to get pointers to unmanaged functions in dll_1 in managed code, pack it into structure, and send this structure as an argument to unmanaged function in dll_2. Have anyone dealt with that kind of problem before maybe?

A: 

Since you don't do anything in managed code but the DLLs live in the same process, just use an IntPtr (is automatically 32 or 64 bits depending on the platform) to pass the unmanaged pointer around. You can of course also insert the IntPtr into your struct and use it as argument or return value when using an external call (e.g. [DllImport('YourDll')] static extern IntPtr ImportedFunction();).

However, to give you more information, it would be necessary to know more about the DLL calls and their data structures.

Lucero
...but make sure the DLL's really share the same process (and apartment if you're doing COM)...
Pontus Gagge
@Pontus, you're of course right, but passing around unmanaged pointers is not a typical COM task, and dealing with mixed address spaces isn't either. So I was just assuming the simple/obvious case.
Lucero
Everything You wrote was right ;) thanks.
Bart Socha