473,395 Members | 1,670 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,395 software developers and data experts.

UnManaged VC++ to call C# DLL

Hi,

I want to create a "dynamic" unmanaged VC++ wrapper that can call any C#
DLL.

I'm thinking that I call the the wrapper from another program like this:
dllcall(name_of_wrapper_function , name_of_C#function_parms_to_be_handled)
First off I want to know if my idea is possible, but a simple example would
be nice. :)

My knowledge in VC++ is very limited, but I have this code from a example.
This works but as you can see the it is some very simple functions:

<<-- CODE -->>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

const int STRMAX = 255;
static char* m_buffer;

// Definition of the Dynamic Link Library Initialization function - LibMain.
// This is called only once - when the XAL statement DllOpen is called for
// the first time. Any further calls of DllOpen will not result in calls to
// the LibMain function until the XAL statement DllClose has been called.
BOOL APIENTRY DllEntryPoint( HINSTANCE hinstDll,
DWORD fdwRreason,
LPVOID plvReserved)
{
switch (fdwRreason)
{
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
return 1;

case DLL_PROCESS_ATTACH:

TRACE0("CPPXAL.DLL Initializing!\n");

// Put initialization code here (Run the first time DllOpen is
called)
// for each process
m_buffer = (char*)malloc(STRMAX*sizeof(char));
if( NULL == m_buffer )
return 0;
else
return 1;

case DLL_PROCESS_DETACH:
free(m_buffer);
return 1 ;
}
return 0;
}

extern "C" char* FAR PASCAL EXPORT STR2UPPER(long unused, const char*
parameter)
{
m_buffer = AnsiUpper((char*)parameter);
return m_buffer;
}

extern "C" char* FAR PASCAL EXPORT STR2LOWER(long unused, const char*
parameter)
{
m_buffer = AnsiLower((char*)parameter);
return m_buffer;
}
>>-- CODE --<<
Best regards
Mads
Aug 2 '06 #1
1 2357
Hi Mads!
I want to create a "dynamic" unmanaged VC++ wrapper that can call any C#
DLL.
First: You need to host the CLR into your process either indirect (via
/clr compiler flag) or by direct (via CLR-Hosting).
http://www.gotdotnet.com/team/clr/ab...r_Hosting.aspx

Then you can call whatever you want via Reflection / System.Activator

Greetings
Jochen
PS: Multiposting is very bad...
Aug 2 '06 #2

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

Similar topics

2
by: Weston Fryatt | last post by:
(Sorry for spamming multiple groups, But I need a solution to this problem) I think this should be a simple question on Memory Allocation in a managed DLL and passing a memory pointer over to an...
4
by: repstat | last post by:
Hi I have a project which is going to be doing some string manipulation which needs to be pretty fast. The user interface is going to be written in C#. I am going to write the string handling...
4
by: | last post by:
I am stuck in a situation and I do believe that this should work, but it doesn't. I have a unmanaged dll, that uses MFC. This works great. Now I recompile the unmanaged dll so it contains...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
4
by: gmclean | last post by:
I have VC++ project that is unmanaged. I would like to build components like user interface dialog boxes in VB .net and call them from the unmanaged VC++ application. Is this possible? Before .net...
3
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
2
by: querry | last post by:
Hi all, I am developing a Windows Form Application in VC++. I am using using Visual Studio 2005. My project requires me to use the Boost Libraries www.boost.org] These boost libraries are...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.