473,799 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_functi on , name_of_C#funct ion_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_ATTA CH:
case DLL_THREAD_DETA CH:
return 1;

case DLL_PROCESS_ATT ACH:

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

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

case DLL_PROCESS_DET ACH:
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 2379
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.Activato r

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
2300
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 unmanaged DLL. I have a "Unmanaged" Client DLL that I'm creating a Managed "wrapper" to be used in VB.Net and/or C#.. In the my Client DLL (unmanaged), There are several functions where I need to allocate a "client side" memory buffer to...
4
7182
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 functions in a C++ DLL. My first question is, if I insert a C++ project into my C# solution, how will VS.NET know that I want it to be unmanaged code? I intend to be calling the DLLs functions using DllImport. I've heard that you can have unmanaged...
4
2182
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 mixed mode managed/unmanaged code, but only use unmanaged code, but this gives a error the moment I want to display a MFC dialog box: Something like unreferenced object,... during runtime.
1
1656
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 code which works well. I understand the basic concept: our code is unmanaged, Windows Forms is Managed and Unmanaged may not call Managed code. I read about Wrappers, PInvoke, Runtime Callable Wrappers for COM and about It just
4
1038
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 I would have done this with an activex object or com object. Any suggestions would be appreciated. George McLean
3
2783
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 question.
9
3123
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 this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
3
4713
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 application. Furthermore, I use a pointer to an unmanaged function to jump back into the managed dll. The managed part is basically a remoting enhancement which asynchronly
2
1048
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 unmanaged code, where as my application itself is managed code. I have a seperae set of unmanaged classes doing the bulk of the work. Now I want to use these classes form the managed class of my application. Let me give a example... Say I have a form and...
0
9538
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,...
1
10214
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9067
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
7561
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
6803
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
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
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
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
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.