473,835 Members | 1,876 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
10 5777
Hi,

I managed to resolve the problems I've been facing so I thought I'd post it
here in case someone else runs into them.

1. I was using a class defintion - this is wrong (come to think about it)..
it should have been declared a Module [ as a result, the private members were
inaccessible and hece my "access violations". Decalring it as a module caused
the private members to be declared during the DLL Load and accessible
thence.] :)

2. the signature "int AppInitFn(int argc, char** argv)" should be
implemented as follows : Public Function(ByVal argc as Int32,
<MarshalAs(Unma nagedType.LPArr ay, ArraySubType:=U nmanagedType.LP Str,
SizeParamIndex: =0)ByVal argv() as string) as Int32

I was so sure that the "char** argv" passed through traditional C/C++ is a
string array but the "Access Violation" because of 1 kept throwing me off :)

I tried the "Public Function(ByVal argc as Int32, ByVal/byRef argv as
IntPtr) as Int32" but eventhough I got the value of argc as "3", i could only
marshal the first parameter through the Marshal.PtrToAN SI call....

So the above defintion tell the Interop to marshal char** argv as a array of
LongPointers (LPArray) with subtype as LPStr (null terminated string) and use
the first parameter "argc" to define the size of this array... Phew.

Hope this helps.
--
Ravi Shankar
"Ravi Shankar" wrote:
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 26 '07 #11

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

Similar topics

7
3313
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
1750
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
2110
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
1179
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
5502
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
4157
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
3515
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
9264
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
9652
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10808
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
10233
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9344
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...
0
5636
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
5804
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4433
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
2
3993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3088
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.