I have explored the dynamic library of Solaris, HP, Windows. For the Unix platforms such as Soloaris, HP, mainly Make files, and Windows also requires a resort.
This column mainly implements a dynamic library and a running program for calling dynamic libraries. The dynamic library includes myTime.h, mytime.cpp, and DLLT1.CPP is required under Windows, this contains DLLMAIN portfral functions of the dynamic library,
Stdafx.cpp, stdafx.h is a file related to the precompilation. Runners include Dy.cpp including calls to dynamic libraries.
Let's talk about the compilation instructions under UNIX. One. Use the HP's own ACC compiler RM * .CPP // z generate the * .o file required by HP under HP under HP.
ACC -B -O libmy.sl mytime.o // - b generates dynamic libraries, -o libmy.sl means that the name of the generated dynamic library is libmy.slacc dy.cpp libmy.sl // is generated with Dy.cpp libmy.sl The executable program, default is A.out, or you can also use -O to specify name
two. Under Solaris Platform under SOLoaris CC. cc -c mytime.cpp // - c generates dynamic library required * .o file cc -g -o libmy.so mytime.o -b generated dynamic library, name Libmy.socc -BDynamic -o myee libmy.so dy.cpp // Generate executable MYEE LN -S /EXPORT/HOME/HURH/TDLL/LIBMY.SO / LIB / / SOLARIS to use root user before running Dynamic library libmy.so then talk about the problem that the dynamic library under Windows needs to be considered, compile with VC. Mainly talk about dynamic library head file MyTime.h's statement #ifndef mytime_h
#define mytime_h
#ifndef Win32
#define dllt_api __declspec (dllexport)
#ELSE
#ifdef jesterdll
#define dllt_api __declspec (dllexport)
#ELSE
#define dllt_api __declspec (dllimport)
#pragma comment (Lib, "DLLT1.LIB")
#ENDIF
#ENDIF
Struct DateType
{
Int year;
Int mon;
Int day;
}
Struct TimeType
{
Char Hour;
Char min;
CHAR Sec;
}
INT DLLT_API GETDATE (DateType * D);
INT DLLT_API GETTIME (Timetype * T);
Class DLLT_API GQLASS {
PUBLIC:
INT ineid;
Void SetNeid (INT NEID);
gqlass ();
~ gqlass ();
}
#ENDIF
Macro Win32, JesterDLL needs to be specified in the dynamic library compilation. The class or function that needs to be exported for dynamic libraries requires modification __declspec (DLLEXPORT), and for the reference to __declspec (dllimport), which is the purpose of our joint win32, JesterDLL, the name of the dynamic library is DLLT1. DLL If you have #pragma comment (lib, "dllt1.lib"), you don't need to contact the DLLT1 library in the Make file.
Other aspects are relatively simple, you can see attachments Crossdll2.rar
==== Not found where the attachment is posted, there is only the Copy part of the code here.
Need crossdll2.rar full code Email contact me
//mytime.cpp
#include "stdafx.h"
#include "time.h"
#include "mytime.h"
Int getdate (datetype * d)
{
Long Ti;
StructTM * TM;
Time (& Ti);
TM = localtime (& ti);
D-> Year = TM-> TM_YEAR 1900;
D-> MON = TM-> TM_MON 1;
D-> day = tm-> TM_MDAY;
Return 0;
}
INT getTime (TimetyPE * T)
{
Long Ti;
StructTM * TM;
Time (& Ti);
TM = localtime (& ti);
T-> Hour = Tm-> TM_HOUR;
T-> min = Tm-> TM_MIN;
T-> sec = tm-> tm_sec;
Return 0;
}
GQLASS :: GQLASS ()
{
INEID = 0;
}
GQLASS :: ~ gqlass ()
{
}
Void GQLASS :: SetNeid (int neid)
{
ineiD = neid;
}
//dy.cpp
#include "stdafx.h"
#include "stdio.h"
#include "../dllt1/mytime.h"
int main ()
{
DateType D;
TimeType T;
Void * DP;
Char * error;
PUTS ("Dynamic Link Library Application Demonstration");
GetDate (& D); / * Call this sharing function * /
Printf ("Current Date:% 04D-% 02D-% 02D / N", D.Year, D.MON, D.DAY;
GetTime (& T); / * Call this sharing function * /
Printf ("Current Time:% 02D:% 02D:% 02D / N", T. Hour, T.MIN, T. SEC);
GQLASS GQ;
Printf ("Before setneid gq.ineid =% d / n", gq.ineid;
Gq.setneid (123);
Printf ("after setneid gq.ineid =% d / n", gq.ineid;
Return 0;
}