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

mixed dll loading problem

Hi all,
i have a managed c++ dll using both managed and unmanaged code and an
unmanaged application that calls the unmanaged code of the managed dll.
I did follow http://support.microsoft.com/kb/814472/en-us but still the
application crashs before the first call of the unmanaged code.

MainFrame.cpp: (unmanaged application)
bool WillUseManagedWrapper()
{
// Snippet 1
typedef void (__stdcall *MixedModeBrokenInit)();
typedef void (__stdcall *pfnEnsureInit)(void);
// ... initialization code
HMODULE hDll = ::GetModuleHandle("ManagedWrapper.dll");
if(hDll)
{
MixedModeBrokenInit pfnDll =
(MixedModeBrokenInit)::GetProcAddress(hDll, "EnsureInitManagedWrapper");
if(pfnDll)
{
pfnDll();
}
else
return false;
}
else
{
DWORD errCode = ::GetLastError();
return false;
}
// ... more initialization code
return true;

}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
WillUseManagedWrapper();
Unmanaged::JustAClass cppWrapp("mönötsched",54);
....
}
MixedModeIsBroken.h: (from the mixed mode dll)
#ifndef PANDATEST_MIXEDMODEISBROKEN_H_INC_
#define PANDATEST_MIXEDMODEISBROKEN_H_INC_

#pragma once
#ifdef MANAGEDWRAPPER_SELF
//AFX_CLASS_EXPORT
#define MANAGEDWRAPPER_API __declspec(dllexport)
#else
//AFX_CLASS_IMPORT
#define MANAGEDWRAPPER_API __declspec(dllimport)
#endif
MANAGEDWRAPPER_API void __cdecl EnsureInitManagedWrapper();
MANAGEDWRAPPER_API void __cdecl ForceTermManagedWrapper();
#endif
MixedModeIsBroken.cpp:
// This is the main DLL file.
#include "stdafx.h"
#define MANAGEDWRAPPER_SELF
#include "MixedModeIsBroken.h"
#include <windows.h>
#include <_vcclrit.h>
// Call this function before you call anything in this DLL.
// It is safe to call from multiple threads; it is not reference
// counted; and is reentrancy safe.
void __cdecl EnsureInitManagedWrapper()
{
// Do nothing else here. If you need extra initialization steps,
// create static objects with constructors that perform
initialization.
__crt_dll_initialize();
// Do nothing else here.

}
// Call this function after this whole process is totally done
// calling anything in this DLL. It is safe to call from multiple
// threads; is not reference counted; and is reentrancy safe.
// First call will terminate.

void __cdecl ForceTermManagedWrapper(void)
{
// Do nothing else here. If you need extra terminate steps,
// use atexit.
__crt_dll_terminate();
// Do nothing else here.

}
ManagedWrapper.h (from the mixed mode dll)
#include <string>
#include "MixedModeIsBroken.h"
namespace Unmanaged
{
class MANAGEDWRAPPER_API JustAClass
{
public:
JustAClass(std::string const& s, int i);
};
}
ManagedWrapper.cpp
// This is the main DLL file.
#include "stdafx.h"

#using <mscorlib.dll>
using namespace System;
#define MANAGEDWRAPPER_SELF
#include "ManagedWrapper.h"
namespace ManagedWrapper{
public __gc class JustAClass
{
public:
JustAClass(String* s, Int32 i);
};

}
ManagedWrapper::JustAClass::JustAClass(String* s, Int32 i)
{
}
Unmanaged::JustAClass::JustAClass(std::string const& s, int i)
{
}
Regards, Arne
Nov 1 '06 #1
0 1280

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

Similar topics

1
by: Mike Kamzyuk | last post by:
Hello all. Basically, I need to call a mixed-mode dll's function (which uses managed code) from a native or mixed-mode dll function (which does not use managed code). I'm wondering if this could...
8
by: Ted Miller | last post by:
Hi folks, I'm looking at moving a large base of C++ code to .Net under tight time constraints. The code runs in mission-critical environments, and I am extremely concerned about the loader lock...
8
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid...
7
by: Staale L. Hansen | last post by:
We have an application which uses some mixed-mode code to expose a .NET 1.1 managed API. Only the necessary files are compiled with /clr. We want to be able to load the application without .NET...
5
by: bonk | last post by:
I have a plain unmanaged exe (no /CLR) that is supposed to to use classes from a mixed mode dll (dll that uses .NET internally). That dll only needs to expose unmanaged interfaces (classes and/or...
0
by: AG | last post by:
Hi, I have implemented the ASP.Net Ihttphandler interface. Handler references the mixed dll (both managed/unmanaged code) that contains core C++ classes wrapped under managed c++ wrappers....
7
by: Kevin Frey | last post by:
Using .NET 1.1. We have a mixed-mode assembly written in Managed C++ that we are using from an ASP.NET application that has been coded using C#. The mixed-mode assembly has its own...
3
by: Mali Guven | last post by:
Hello, I have a native DLL (written in C) which is supposed to call a managed DLL (was written in C#, and an entry point was injected modifying the ildasm'd code). The exectuable calls the...
0
by: emu | last post by:
Hi All, I have an unmanaged C++ application that references a mixed mode image DLL (mixed managed and unmanaged). Under .NET 1.1 we could trust the dll (the mixed mode dll) by running the...
1
by: aircraft | last post by:
Hi folks, I'm trying to load a mixed mode dll from a native c++ application using loadLibrary. If I run the application from the local drive it works without any problem, byt il I run it from the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.