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

Create DLL of a C++ Object

Status
Not open for further replies.

cdlvj

MIS
Nov 18, 2003
676
US
Many examples out there but they all show C functions.

Visual .net 2003.
Created a MFC DLL Project (Shared)
Added myDatabase Class with code.
Add the one function that I want to export InsertData

It Builds.
Do I need to add more to this project?
How do I access this from a client?




Code:
#pragma once

#include <windows.h>
#include <sqlext.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

class myDatabase
{
private:
	HENV                      hEnv; // Env Handle from SQLAllocEnv()
    HDBC                      hDBC; // Connection handle
	int DBOpen;  

	RETCODE OpenDatabase();
	void doSQLState(HSTMT handle);
    RETCODE CommitDatabase();
	int CloseDatabase();


public:
	myDatabase(void);
	~myDatabase(void);
	int InsertData(char *PID, char *system, char *program, char *step, char *message, char *rc, char *dt);
    
};

Code:
; DLLAppLogger.def : Declares the module parameters for the DLL.

LIBRARY      "DLLAppLogger"

EXPORTS
    ; Explicit exports can go here
    	InsertData
 
InsertData() isn't static, so it requires a this pointer to act on - therefore you can't export it.
You can create a global function to export like this:
Code:
int InsertData( myDatabase& thisRef, char *PID, char *system, char *program, char *step, char *message, char *rc, char *dt )
{
   thisRef.InsertData( PID, system, program, step, message, rc, dt );
}
 
If you need to export something from a DLL look for the __declspec(dllexport) in MSDN. I am sure you'll find something.

Anyway you cannot export a function from a class without exporting the class itself.

But exported classes are just for use in another C++ program because the name of exported functions gets mangled with the C++ sintax (look with depends.exe in the resulting dll to understand what I mean).

HTH,

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top