473,379 Members | 1,190 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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(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
Jul 21 '05 #1
4 1576
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 SetCurrentStatistics(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 SetCurrentStatistics
Any further ideas

James
Jul 21 '05 #4
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.
Jul 21 '05 #5

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

Similar topics

2
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....
0
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...
2
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...
4
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...
5
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...
0
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...
7
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...
1
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...
6
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.