PC Review


Reply
Thread Tools Rate Thread

Calling unmanged code in managed code

 
 
=?Utf-8?B?SmFtZXMgTC4gQnJvd24=?=
Guest
Posts: n/a
 
      9th Feb 2004
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
 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      9th Feb 2004
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
=?Utf-8?B?SmFtZXMgTC4gQnJvd24=?=
Guest
Posts: n/a
 
      9th Feb 2004
The unmanaged declarations are the following

typedef struct _MYSTRUCT
__int64 counter1
__int64 counter2
}MYSTRUCT

BOOL SetCurrentStatistics(MYSTRUCT stats

AfxMessageBox("Inside the DLL")
[...


 
Reply With Quote
 
=?Utf-8?B?SmFtZXMgTC4gQnJvd24=?=
Guest
Posts: n/a
 
      9th Feb 2004
Huhhh, sorry. I inserted the wrong code. But the original function TestMarshalling is just the same as SetCurrentStatistics
Any further ideas

James
 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      12th Feb 2004
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I use managed with unmanged code Allen Maki Microsoft Dot NET 1 29th May 2007 06:12 PM
C# App using Mixed Managed C++ crashes when access COM object through interop and unmanged code ropo Microsoft Dot NET 1 24th Nov 2006 11:56 AM
Cannot debug from unmanged code into managed code B. Microsoft VC .NET 6 12th Oct 2006 02:06 AM
Debugging unmanged code (C++) from a managed project (C#) Ed Debrot Microsoft Dot NET Compact Framework 1 13th Oct 2004 10:20 PM
a question about calling unmanged code from managed code chaor Microsoft C# .NET 2 16th Jun 2004 05:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:41 PM.