473,785 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 WillUseManagedW rapper()
{
// Snippet 1
typedef void (__stdcall *MixedModeBroke nInit)();
typedef void (__stdcall *pfnEnsureInit) (void);
// ... initialization code
HMODULE hDll = ::GetModuleHand le("ManagedWrap per.dll");
if(hDll)
{
MixedModeBroken Init pfnDll =
(MixedModeBroke nInit)::GetProc Address(hDll, "EnsureInitMana gedWrapper");
if(pfnDll)
{
pfnDll();
}
else
return false;
}
else
{
DWORD errCode = ::GetLastError( );
return false;
}
// ... more initialization code
return true;

}
int CMainFrame::OnC reate(LPCREATES TRUCT lpCreateStruct)
{
WillUseManagedW rapper();
Unmanaged::Just AClass cppWrapp("mönöt sched",54);
....
}
MixedModeIsBrok en.h: (from the mixed mode dll)
#ifndef PANDATEST_MIXED MODEISBROKEN_H_ INC_
#define PANDATEST_MIXED MODEISBROKEN_H_ INC_

#pragma once
#ifdef MANAGEDWRAPPER_ SELF
//AFX_CLASS_EXPOR T
#define MANAGEDWRAPPER_ API __declspec(dlle xport)
#else
//AFX_CLASS_IMPOR T
#define MANAGEDWRAPPER_ API __declspec(dlli mport)
#endif
MANAGEDWRAPPER_ API void __cdecl EnsureInitManag edWrapper();
MANAGEDWRAPPER_ API void __cdecl ForceTermManage dWrapper();
#endif
MixedModeIsBrok en.cpp:
// This is the main DLL file.
#include "stdafx.h"
#define MANAGEDWRAPPER_ SELF
#include "MixedModeIsBro ken.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 EnsureInitManag edWrapper()
{
// Do nothing else here. If you need extra initialization steps,
// create static objects with constructors that perform
initialization.
__crt_dll_initi alize();
// 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 ForceTermManage dWrapper(void)
{
// Do nothing else here. If you need extra terminate steps,
// use atexit.
__crt_dll_termi nate();
// Do nothing else here.

}
ManagedWrapper. h (from the mixed mode dll)
#include <string>
#include "MixedModeIsBro ken.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(Stri ng* s, Int32 i);
};

}
ManagedWrapper: :JustAClass::Ju stAClass(String * s, Int32 i)
{
}
Unmanaged::Just AClass::JustACl ass(std::string const& s, int i)
{
}
Regards, Arne
Nov 1 '06 #1
0 1314

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

Similar topics

1
2202
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 be accomplished and how. Here's the problem. We have a third party app (TPA) capable of loading native and mixed-mode dlls somehow (we don't know how). It loads our native dll (OND) and allows us to use our code inside the app (that is, we...
8
4525
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 problem and the potential for deadlocks. After pouring over the available information, and trying a few experiments, I am still left with a few questions and issues I hope someone out there can shed some light on.
8
1999
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 the usage of old style COM, my alternative is to expose my unmanaged interface through the CLI, to achieve that I have created a mixed mode DLL in which my unmanaged class are defined. When referencing the DLL just described in another mixed mode EXE...
7
1696
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 present, and then just disable the API. But we are not even able to give an error message when we start the application without mscoree.dll present. We have tried delay-loading mscoree.dll, but that did not help because the OS loader (at least on...
5
3278
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 functions). This is of course no problem and it works fine. However I have the special scenario where the exe needs to be able to run even when there is no .NET Framework installed. The exe is supposed to check at runtime if the .NET Framework is...
0
1297
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. ASP.NET worker process, sometimes while loading the handler and mixed dll associated with it, throws System::DLLNotFoundException. I have verified that all required Dlls are in the system path. I have the handler version up and running perfectly but...
7
1434
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 "initialisation" routine to cater for any potential "mixed-mode DLL loading problem". Some of our code uses thread-local-storage, and in the DllMain for my mixed-mode assembly I did the appropriate initialisation of the thread-local-storage object on...
3
2785
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 native DLL but the native DLL fails to load the managed DLL. The paper that addresses the 'mixed DLL problem' below does not offer any understandable workaround....
0
3003
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 following command line: caspol.exe -polchgprompt off -machine -addgroup 1 -url "file://<UNC path to dll>\mixedMode.dll" FullTrust ame "GroupName" -polchgprompt on
1
1720
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 network it crashes at the moment of loading the mixed mode dll with a System.IO.LoadFileException. I know that the problem comes from the code access security policy and that's not my question :) In fact as I know it's not possible to catch...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
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
9957
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
8983
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
7505
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
6742
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
5386
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
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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

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.