UnManaged VC++ to call C# DLL

M

Mads Westen

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;
}
Best regards
Mads
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top