473,804 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to call managed code from unmanaged c++ code !

Hi,

I have a requirement where I need to call methods written in VB.Net from a
C++ code. I have been going crazy reading various articles on the net w.r.t
interop and marshalling but an more confused now that before.

the signature I need to conform in the VB.Net DLL is
int MyAppInitFunc(i nt argc, char** argv)

To this extent I have tried the following
Public Function MyAppInitFunc(B yVal argc as integer, ByRef argv as string)
as Integer
Public Function MyAppInitFunc(B yVal argc as Int32, ByVal argv() as string)
as Int32

.... based on some posts I even tried
Public Function MyAppInitFunc(B yVal argc as Int32, ByVal argv as IntPtr) as
Int32

but have not been able to get anything to work.

Is there perhaps some reading I'm missing up on ?

Regards.

--
Ravi Shankar
Jun 16 '07 #1
10 5774
I do all my vb6 interop through COM , this works great

maybe this is an idea for you to ?

Regards

Michel

"Ravi Shankar" <sh*********@ne wsgroup.nospams chreef in bericht
news:4F******** *************** ***********@mic rosoft.com...
Hi,

I have a requirement where I need to call methods written in VB.Net from a
C++ code. I have been going crazy reading various articles on the net
w.r.t
interop and marshalling but an more confused now that before.

the signature I need to conform in the VB.Net DLL is
int MyAppInitFunc(i nt argc, char** argv)

To this extent I have tried the following
Public Function MyAppInitFunc(B yVal argc as integer, ByRef argv as string)
as Integer
Public Function MyAppInitFunc(B yVal argc as Int32, ByVal argv() as string)
as Int32

... based on some posts I even tried
Public Function MyAppInitFunc(B yVal argc as Int32, ByVal argv as IntPtr)
as
Int32

but have not been able to get anything to work.

Is there perhaps some reading I'm missing up on ?

Regards.

--
Ravi Shankar

Jun 17 '07 #2
>the signature I need to conform in the VB.Net DLL is
>int MyAppInitFunc(i nt argc, char** argv)
Does that mean the C++ caller expects such a function to be a staticly
exported entrypoint from the DLL? VB doesn't let you do that.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 17 '07 #3
Hello Michel,

Please explain.. I have made my project with "Register for COM Interop". I
have also done a regasm /tlb:.....

All my functions are ComVisible().

Since there is a difference in the VB.Net DLL's and classic Win32 DLL's,
I've even done the IL tweaking to ensure that my functions are being exported.

I can't figure out how to get Char** marshalled into my managed code ?

The combinations Ive tried are
1. <MarshalAs(Unma nagedType.SafeA rray, SafeArraySubTyp e:=VarEnum.VT_B STR)>
ByVal argv as string()

This gives me an error saying SafeArray of rank 11888 has been passed to a
method expecting an array of rank 1

2. <MarshalAs(Unma naged.LPArray)B yRef argv as string

This gives me an error saying cannot marshal 'parameter #2' : Invalid
managed/unmanaged type combination (string parameters and return types must
be paired with LPStr, LPWStr, LPTStr, BSTR, TBStr, VBByRefStr, or AnsiBStr).

and combiantions of the above with char()() instead of string() etc, etc.
x--
Ravi Shankar
"Michel Posseth [MCP]" wrote:
I do all my vb6 interop through COM , this works great

maybe this is an idea for you to ?

Regards

Michel

"Ravi Shankar" <sh*********@ne wsgroup.nospams chreef in bericht
news:4F******** *************** ***********@mic rosoft.com...
Hi,

I have a requirement where I need to call methods written in VB.Net from a
C++ code. I have been going crazy reading various articles on the net
w.r.t
interop and marshalling but an more confused now that before.

the signature I need to conform in the VB.Net DLL is
int MyAppInitFunc(i nt argc, char** argv)

To this extent I have tried the following
Public Function MyAppInitFunc(B yVal argc as integer, ByRef argv as string)
as Integer
Public Function MyAppInitFunc(B yVal argc as Int32, ByVal argv() as string)
as Int32

... based on some posts I even tried
Public Function MyAppInitFunc(B yVal argc as Int32, ByVal argv as IntPtr)
as
Int32

but have not been able to get anything to work.

Is there perhaps some reading I'm missing up on ?

Regards.

--
Ravi Shankar


Jun 17 '07 #4
Hi Mattias,

I has to do some IL tweaking to get my functions exported. Now If I can get
definitions that would permit my variables to be marshalled properly to
unmanaged code, it'd work.
--
Ravi Shankar
"Mattias Sjögren" wrote:
the signature I need to conform in the VB.Net DLL is
int MyAppInitFunc(i nt argc, char** argv)

Does that mean the C++ caller expects such a function to be a staticly
exported entrypoint from the DLL? VB doesn't let you do that.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 17 '07 #5
>I has to do some IL tweaking to get my functions exported. Now If I can get
>definitions that would permit my variables to be marshalled properly to
unmanaged code, it'd work.
OK, assuming you get that part to work, I recommend that you go with
the third method signature you posted (with ByVal argv as IntPtr). You
also have to make sure the calling convention is correct.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 17 '07 #6
Ok so you're suggesting I try

<MarshalAs(Unma naged.LPArray)B yVal argv as IntPtr ?

I'll post the results a little later.

Regards.
--
Ravi Shankar
"Mattias Sjögren" wrote:
I has to do some IL tweaking to get my functions exported. Now If I can get
definitions that would permit my variables to be marshalled properly to
unmanaged code, it'd work.

OK, assuming you get that part to work, I recommend that you go with
the third method signature you posted (with ByVal argv as IntPtr). You
also have to make sure the calling convention is correct.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 18 '07 #7
>Ok so you're suggesting I try
>
<MarshalAs(Unm anaged.LPArray) ByVal argv as IntPtr ?

You can remove the MarshalAs attribute, it has no effect on IntPtrs.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 18 '07 #8
Hi Mattias,

I tried what you've suggested and the program went into a non-terminable
state with continuous error pop-ups stating

Unhandled Exception at 0x008f213a in ....exe: 0xC0000005: Access violations
reading loactions 0x00000000

Which sound like a "null" pointer exception to me in a different package :)

Regards,
--
Ravi Shankar
"Mattias Sjögren" wrote:
Ok so you're suggesting I try

<MarshalAs(Unma naged.LPArray)B yVal argv as IntPtr ?


You can remove the MarshalAs attribute, it has no effect on IntPtrs.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 19 '07 #9
Any more recommendations ?
--
Ravi Shankar
"Mattias Sjögren" wrote:
Ok so you're suggesting I try

<MarshalAs(Unma naged.LPArray)B yVal argv as IntPtr ?


You can remove the MarshalAs attribute, it has no effect on IntPtrs.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 21 '07 #10

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

Similar topics

7
3312
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
2
1749
by: hykim | last post by:
I want to call a unmanaged dll's function returning some STRUCT's pointer. the next is definition of a STRUCT. ----------------------------------------------------------------------- typedef struct myStruct{ struct { UINT_PTR anything; UCHAR anything2; } myInnerStruct;
3
2109
by: Tony Liu | last post by:
Dear All: I create a very simple DLL by using EVC to test the problem. (The platform I am working for those program is WinCE.NET) ******************************************************* The header looks like: #ifdef TESTDLL_EXPORTS #define TESTDLL_API __declspec(dllexport)
0
1178
by: Stephen Horne | last post by:
I've only very recently started with .NET, and need to use some existing container libraries in new code. I'd like to minimise the amount of porting, but of course these containers are not designed to work in a .NET managed way. They make extensive use of pointer arithmetic, placement new and various other techniques that are obviously incompatible with managed code. If possible, I'd like to find a way of storing managed objects within...
1
5499
by: Tim Rogers | last post by:
We've currently got a C++ client/server app that uses DCOM in order to make remote calls. We want to replace DCOM with a .NET Web Service. The server piece seems clear to me. I can write it using MC++ and then can call my native C++ server code from within the Web Service. What I am unsure about is the client piece. The GUI is written in C++. Will I be able to call the Web Service from native C++ code? At first, I thought I would...
13
4152
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
3
3513
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust ------------------------------------------------------------------------
0
1462
by: Ken Durden | last post by:
A little more info. I have a unmanaged C++ DLL, compiled without /CLR. Inside a Managed C++ DLL, I have the following class: MarshalWrapper.h ---- #ifdef _MANAGED __nogc #endif
22
9262
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. I'm sure the problem is the way i'm using the sendmessage API, the return string and the lParam return 0....is anybody have a clue? any sendmessage api expert here? public static extern Int32 FindWindow(String lpClassName,String
0
10558
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2975
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.