Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem loading my dll with LoadLibrary

Status
Not open for further replies.

Svavar

Programmer
Jan 8, 2004
1
0
0
IS
Hi

I'm having problem loading my dll with LoadLibrary. I have got a dll compiled in MSVC 6.0 and when I use that I have no problem loading it with LoadLibrary. Now I am building the dll with MSVC .net and when I try to load the dll I get
error 182 : "The operating system cannot run %1". Also known as ERROR_INVALID_ORDINAL. I have no clue what is wrong. The dll compiles and builds fine but I can't load it. If you have any solutions for me it would be great. I suspect some build parameter but don't know which.

best regards
Svavar
 
You could try using
Code:
__declspec( dllimport )
for using specific functions/variables within the dll instead of the LoadLibrary function. This would require you to change a few things in your library header file:
Code:
/*
   lib.h - Library Header file.
*/

#ifdef DLLEXPORT
  // Export if in library.
  #define DLLAPI __declspec(dllexport)
#else
  // Import if not in library.
  #define DLLAPI __declspec(dllimport)
#endif

// Function prototypes
DLLAPI int LibFunction(void);
// etc...
In your library source file you have to do two things:
1) Define DLLEXPORT before you include your header file.i.e.
Code:
#define DLLEXPORT
#include "lib.h" // what your header is called.
2) For all the functions/variables you want to export, type DLLAPI before declaring them. For example:
Code:
DLLAPI int LibFunction(void)
{
  // Do something in here
}
3) Recompile the library source and get a DLL (hopefully).

Now, to access any of the functions in the DLL from another C program, you have to #include the library header without defining the DLLEXPORT. This will import all the functions/variables stated in the header. You can call these functions normally from the C program now.

I think this method is probably a better approach as it saves needing to use the GetProcAddress function for calling a function. :)

 
adholioshake, you can get troubles with this lines of code:
#ifdef DLLEXPORT
// Export if in library.
#define DLLAPI __declspec(dllexport)
#else
// Import if not in library.
#define DLLAPI __declspec(dllimport)
#endif

Imagine you're using this dll from some other dll application. The main idea is to use instead of your DLLEXPORT some MYDLL_IMPL which will be unique for each dll project and define it in the stdafx.h of mydll.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top