Calling unmanged code in managed code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I'm currently working on a project, that contains one .net (VB) executable and a C++ (MFC) DLL. Now, what I want to do is to call the functions in the dll out of my managed code
//managed code (the unmanaged code declarations are just the same - but unmanaged)
Public Class Win32Call
<StructLayout(LayoutKind.Sequential)>
Class MYSTRUC
Public counter1 As Int6
Public counter2 As Int6
End Clas

Declare Function TestMarshalling Lib "test.dll" (ByVal stats As MYSTRUCT) As Boolea
End Clas

//[...
dim s as New Win32Calls.MYSTRUC
//filling s..
Win32Calls.TestMarshalling(s) '!!!

At this point, the debugger throws a System.NullReferenceException - can anyone tell me why?

Thanks a lo
James
 
James,
//managed code (the unmanaged code declarations are just the same - but unmanaged):

Please post the unmanaged declarations as well. Things aren't always
equal even if they look more or less the same in different languages.



Mattias
 
The unmanaged declarations are the following

typedef struct _MYSTRUCT
__int64 counter1
__int64 counter2
}MYSTRUCT

BOOL SetCurrentStatistics(MYSTRUCT stats

AfxMessageBox("Inside the DLL")
[...
 
Huhhh, sorry. I inserted the wrong code. But the original function TestMarshalling is just the same as SetCurrentStatistics
Any further ideas

James
 
James,
BOOL SetCurrentStatistics(MYSTRUCT stats)

If the function is using the default _cdecl calling convention, you
should add CallingConvention=CallingConvention.Cdecl to the C#
DllImport attribute.



Mattias
 
Back
Top