473,569 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling unmanged code in managed code

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(L ayoutKind.Seque ntial)>
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.MYST RUC
//filling s..
Win32Calls.Test Marshalling(s) '!!!

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

Thanks a lo
James
Jul 21 '05 #1
4 1596
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.
Jul 21 '05 #2
The unmanaged declarations are the following

typedef struct _MYSTRUCT
__int64 counter1
__int64 counter2
}MYSTRUCT

BOOL SetCurrentStati stics(MYSTRUCT stats

AfxMessageBox(" Inside the DLL")
[...
Jul 21 '05 #3
Huhhh, sorry. I inserted the wrong code. But the original function TestMarshalling is just the same as SetCurrentStati stics
Any further ideas

James
Jul 21 '05 #4
James,
BOOL SetCurrentStati stics(MYSTRUCT stats)


If the function is using the default _cdecl calling convention, you
should add CallingConventi on=CallingConve ntion.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.
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1347
by: Peter Schmitz | last post by:
Hi, I just created a solution that is based on unmanaged C++ code. Now, the .net framework consists of some cool functions and classes - there is especially one namespace I'd like to use. That's why I'm currently trying to figure out what's the best way to use this managed code snippet. Is it possible to create a managed Dll (in any...
0
242
by: P Reddy | last post by:
Hi All, Greetings!!! I have a question. Please respond.... I am trying to write a C# component that need to inherit some of the the interfaces from unmanged code(VC). I think one way to resolve this is to port unmanged interfaces and header files in to manage C++ as Visual Studio allows porting and compiling all this
2
2945
by: Paul Sneddon | last post by:
Hi, I'm using VS.NET 2005 RC to create Windows Mobile apps. I'm trying to call the following shell function which is new on Windows Mobile 5. SNDGETSND http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mobilesdk5/html/wce51lrfSndSetSound.asp I basically just need to be able to get the device ringer mode (e.g. On Off...
4
337
by: James L. Brown | last post by:
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...
5
3406
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most part attempting to do what is this article by Nish: http://www.voidnish.com/articles/ShowArticle.aspx?code=cbwijw I have to hook up a unmanaged...
0
877
by: adebaene | last post by:
Hello group, I am writing a managed C++ DLL (VC2003) that is to be called from native code and uses some .NET 3rd party library. All runs fine and smooth, except when I try to call ::SetLastError from managed code (the API of the DLL is "C", and I'd like to use the GetLastError mechanism to communicate errors back to client). It seems...
7
2551
by: brian_harris | last post by:
I have a string object that I need to convert into an unmanged char * to be used by several unmnaged 3rd party functions. I have tried to use: (Marshal::StringToHGlobalAuto (Profname)) This would get me an IntPtr value, but I could not find the correct way to cast an IntPtr to an unmanged char *. One example I tried was: char *inifile;...
1
1191
by: mschuck | last post by:
Here is the scenario I'm trying to make work. I've got 2 managed C++ classes, each of which wrappes an unmanaged C++ class, kind of like so: __nogc class UnmanagedClassA { public: void SetUnmanagedB( UnmangedClassB* val ); ....
6
1542
by: B. | last post by:
my small project has two files, umg.cpp (unmanaged c++) and mged.cpp (MC++), and unmanged code will call managed code. However, I cannot debug from unmanged code into managed code. Can anyone help me to solve the problem?
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.