473,511 Members | 16,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a dll from a dll

3 New Member
I created a dll named test.dll using c++ with this interface

FunctionBlock* createBlock() ;

Then I wrote a test program to use it and it was successful.

I created another dll named test2.dll with the same way which used test.dll.

But LoadLibrary returned null in when it is called in test2.dll.

Do you have an idea about what the problem is?
Sep 10 '07 #1
3 2073
weaknessforcats
9,208 Recognized Expert Moderator Expert
It's a path issue. Have you called SetDllDirectory() before calling
LoadLibrary() ??

LoadLibrary() uses a standard search scheme and if you haven't got the dll path set up you need to hard-code it in the LoadLIbrary() call.
Sep 10 '07 #2
phoenix7
3 New Member
Here is my code:
Expand|Select|Wrap|Line Numbers
  1. typedef FunctionBlock* (*CreateInstance)();
  2. FunctionBlock* createBlock() 
  3. {
  4.     CreateInstance createInstance;
  5.  
  6.     HINSTANCE hInstLibrary = LoadLibrary(L"C:\\newproject80\\output\\cpp\\FFB2000\\FFB.dll");
  7.  
  8.     if (hInstLibrary)
  9.     {
  10.         DoSomething();
  11.         FreeLibrary(hInstLibrary);
  12.     }
  13.     else
  14.     {
  15.         cout << "DLL Failed To Load!" << std::endl;
  16.     }
  17. }
  18.  
When it is called directly from a console application DoSomething() will be called.
And when it is called inside a dll It outputs "DLL Failed to Load".

I added SetDllDirectory but nothing changed!
Sep 12 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
This is the function prototype for LoadLibrary:
HMODULE WINAPI LoadLibrary(
LPCTSTR lpFileName
);
Your call assigns to an HINSTANCE and not an HMODULE.

The arguiment is an LPTCTSR (a long pointer to a const TCHAR string). You have provided:
HINSTANCE hInstLibrary = LoadLibrary(L"C:\\newproject80\\output\\cpp\\FFB20 00\\FFB.dll");
which is a wchar_t string. Not good.

Your code should be:

Expand|Select|Wrap|Line Numbers
  1. HMODULE hInstLibrary = LoadLibrary(TEXT("C:\\newproject80\\output\\cpp\\FFB2000\\FFB.dll"));
  2.  
LoadLibrary is a macro that resolves to LoadLibraryA or LoadLibraryW based on the character set (char or wchar_t) used on the build. The TEXT is a TCHAR macro that provides a char string when the build character is char and provodes a wide string when the build character set is multi-byte.

Try this and let me know what happened.

BTW: I hope you are using an _tmain() and all those _t functions.
Sep 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2303
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
8
2936
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
7
6582
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
3396
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
9051
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
2
3137
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
47
4899
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
7
2663
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
10
3235
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
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...
0
7355
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,...
1
7081
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...
0
7510
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...
0
4737
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...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
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 ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.