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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access LIB functions through DLL

Status
Not open for further replies.

JimmyFo

Programmer
Feb 14, 2005
102
US
Hi, I am trying to expose the functions in a .lib file I have through a .dll file. This is because the program I am working with (Progress 4GL) can not utilize .lib files - it can only call .dll files.

My question is, how can I create a DLL that exposes the .lib functions? I would like to create a DLL project, load the .lib (?) and then call the .lib functions from within an exposed DLL function. Can I do this?

Thanks,
James
 
Thanks, I've done some work on it. I used HMODULE and LoadLibrary to open the .lib file inside one of the exported functions and I now have an error.

The lib has a namespace defined in it (called "oralib") and to use the .lib's functions, I need to do something like:

oralib::connection cn;

When I do this after the LoadLibrary, it says "namespace 'oralib' not defined'". Do you know why this is?

Thanks,
James
 
Hi, let me clarify some of the code I'm using:

DLLCode.h

Code:
#pragma once

#ifdef DLLDIR_EX
   #define DLLDIR  __declspec(dllexport)   // export DLL information
#else
   #define DLLDIR  __declspec(dllimport)   // import DLL information
#endif 

// The extern "C" declaration allows mixed languages compactability,
// it prevents the C++ compiler from using decorated (modified)
// names for the functions 
extern "C" { 
       void DLLDIR InsertToOracle();
}; 

class DLLDIR DLLclass
{
   public:
      DLLclass();				// Class Constructor
      ~DLLclass();				// Class destructor
      int CreateInsert();	// Class function Add
};

DLLCode.cpp

Code:
#include "Stdafx.h"
#include "DLLCode.h"
#include <iostream> 

using namespace std; 

void InsertToOracle()
{
	HMODULE hMod;				//Handle to library module
	BOOL bRes;					//Check if unloaded successfully
	hMod = LoadLibrary("oralib.lib");

	oralib::connection cn;

	cn.open ("server_name", "scott", "tiger");
	cn.execute ("create table temp_table ( n numeric )");
	cn.execute ("insert into temp_table values (1)");
	oralib::resultset &rs = *cn.select ("select * from temp_table");
	// ...
	rs.release ();
	cn.execute ("drop table temp_table");

	bRes = FreeLibrary(hMod);
}; 


DLLclass::DLLclass()
{
}; 
DLLclass::~DLLclass() {}; 

int DLLclass::CreateInsert()
{
	int b = 1;
	return b;
};

Question: what is the difference of DLLImport and LoadLibrary?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top