472,986 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

.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 FileNotFoundException. 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 3106
sunil s via DotNetMonster.com 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 FileNotFoundException. 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(dllexport)) not for managed, __clrcall,
methods. If the managed DLL is written in managed C++ then you can put
__declspec(dllexport) 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(dllexport) 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.bet 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
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: Paul | last post by:
Hi all may I know how to use C# DLL inside my VC++ Project ? Thanks in advance.
3
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...
1
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...
13
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...
2
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. ...
28
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...
4
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...
1
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...
5
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.