473,545 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.net dll call from native c++

Hi,

I've got a native C++ app which calls a 3rd parth .NET DLL using the
LoadLibrary/GetProcAddress functions. This works fine when the DLL is
located in the app directory, but if I move it out to it's own directory,
then I get a FileNotFoundExc eption. I've tried manipulating the
app.exe.config file's <codebase> parameter, but this doesn't seem to have
any effect, possibly because the DLL does not have a strong name. The only
thing that does work is manipulating the DEVPATH variable/machine.config
file, but I don't think that this is what DEVPATH was designed for. I
cannot guarantee where the app will be run from but I do know that the DLL
will always be found in a fixed directory path. How do I get my app to
read the DLL?

Sunil

--
Message posted via http://www.dotnetmonster.com
Jul 21 '05 #1
1 3194
sunil s via DotNetMonster.c om wrote:
Hi,

I've got a native C++ app which calls a 3rd parth .NET DLL using the
LoadLibrary/GetProcAddress functions. This works fine when the DLL is
located in the app directory, but if I move it out to it's own
directory, then I get a FileNotFoundExc eption. I've tried
manipulating the app.exe.config file's <codebase> parameter, but this
doesn't seem to have any effect, possibly because the DLL does not
have a strong name. The only thing that does work is manipulating
I am a bit unsure about what you are doing. You have an unmanaged C++
process and you want to load a managed library assembly. How are you
executing the code? How do you load the managed classes in the managed
library assembly? Are you hosting the runtime and using COM interop to
get the class?

Why are you using GetProcAddress? GetProcAddress is for unmanaged
exported functions (__declspec(dll export)) not for managed, __clrcall,
methods. If the managed DLL is written in managed C++ then you can put
__declspec(dlle xport) on a global function that will be compiled to IL
and get access to it via GetProcAddress. When the function is called the
runtime will be initialized, however, DO NOT DO THIS! There is a serious
bug in .NET and Windows that will potentially cause a deadlock. This bug
won't be fixed until Whidbey. You can get round this bug (the mixed mode
loader bug), but it involves separate initialization of unmanaged global
variables and the CRT, and its messy.

As to your question. Fusion is a replacement for
LoadLibrary/GetProcAddress and the sections in the config file are used
to configure Fusion. Those settings have no effect at all on
LoadLibrary. LoadLibrary is configured through the PATH environment
variable and a redirect file (an empty file with the name of the process
and .local as the extension that indicates that LoadLibrary should only
pick up DLLs from the application folder).
the DEVPATH variable/machine.config file, but I don't think that this
is what DEVPATH was designed for. I cannot guarantee where the app
will be run from but I do know that the DLL will always be found in a
DEVPATH is a horrible hack, and as you have said, it is not intended for
doing what you are trying to do. It will be removed in later versions of
..NET
fixed directory path. How do I get my app to read the DLL?


I need more information about what you are trying to do. From, your
description I think that you are trying to call a global function in a
library assembly that contains IL and has been exported with
__declspec(dlle xport) if this is the case you are storing up trouble. It
would be better to export a static method from a class, host the runtime
and call the COM Callable Wrapper.

Here's a tutorial on Fusion that you might find useful and explains some
of the issues I have mentioned above:

http://www.grimes.demon.co.uk/workshops/fusionWS.htm

Richard
--
www.richardgrimes.com
my email ev******@zicf.b et is encrypted with ROT13 (www.rot13.org)
Jul 21 '05 #2

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

Similar topics

1
2184
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...
8
19877
by: Paul | last post by:
Hi all may I know how to use C# DLL inside my VC++ Project ? Thanks in advance.
3
3883
by: Richard A. Lowe | last post by:
Hi all (sorry I haven't been around lately for those who know me, life happens :) I have to call a native DLL (written > 5 years ago, not by me, and all source lost) that is currently being called from a Java application also written about 5 years ago (I think Borland JBuilder 4 was the IDE - Java 1.2 perhaps?). The Java declaration looks...
1
5488
by: Tim Rogers | last post by:
We've currently got a C++ client/server app that uses DCOM in order to make remote calls. We want to replace DCOM with a .NET Web Service. The server piece seems clear to me. I can write it using MC++ and then can call my native C++ server code from within the Web Service. What I am unsure about is the client piece. The GUI is written...
13
4104
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain...
2
2502
by: Marek | last post by:
Hi I'm trying to call a native C++ dll using the following code (both C# and C++ code segments included). When I make the call to the method (AddTwoDoubles) that has no return value all is fine. When I try and call a function that returns a double (AddTwoDoubles2) I get the following message: PInvokeStackImbalance was detected Message:...
28
1926
by: Peter Olcott | last post by:
I want to double check my understanding about how the .NET framework works. From what I understand every call to the .NET framework is ultimately translated into one of more API calls, is this correct?
4
5252
by: Steve Richter | last post by:
I have a C++ forms project that I am adding some unmanaged code to. I have a member function of the Form1 class that returns a String^ holding the text of the last win32 error. The code is failing on the call to FormatMessage. Cannot marshal 'parameter #7': Pointers cannot reference marshaled structures. Use ByRef instead. how do I...
1
5631
by: cctv.star | last post by:
I need to dynamically load and call .NET assembly from native application, written in C++. I'm trying to do this by creating a (managed) module, written in C++/ CLI, whose header can be #included from native code like normal C++ header, and whose .cpp file uses C++/CLI to actually load and call .NET assembly. It kind of works right now,...
5
11033
by: =?Utf-8?B?SmVmZg==?= | last post by:
Well - from my initial research, this doesn't seem to be an easy solution if it is doable at all. I have .NET 2.0 C# Classes compiled into DLLs. I also have older unmanaged (non-.NET) C++ code which I would like to have use the code in those C# DLLs. Anyone have a step-by-step simple example for doing such?
0
7409
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...
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
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...
1
7436
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...
0
5981
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...
0
4958
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...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1897
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
0
715
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...

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.