The dll library is often used in work, but because it is often unable to remember, it is often necessary to query information. Now, in my blog, write down how to create a non-MFC dynamic link library.
1. Create a Win32 dynamic-Link Library Project in VC ++;
2. Add the ucdll. h and ucdll. cpp files to the created Project;
3. ucdll. H content:
# Ifndef ucdll_h
# Define ucdll_h
// Extern "C" Void _ declspec (dllexport) transfor (char * srcfile, char * dstfile );
Extern "C "{
Void _ declspec (dllexport) transfor (char * srcfile, char * dstfile );
Int _ declspec (dllexport) add (int A, int B );
}
# Endif
4. ucdll. cpp file content:
# I nclude "ucdll. H"
# I nclude "stdlib. H"
# I nclude <memory. h>
# I nclude "stdio. H"
Int add (int A, int B)
{
Return (A + B );
}
Void transfor (char * srcfile, char * dstfile)
{
File * RFP;
File * WFP;
Unsigned short length;
Unsigned char * SRC, * DST;
If (RFP = fopen (srcfile, "rb") = NULL)
{
Return;
}
If (WFP = fopen (dstfile, "WB") = NULL)
{
Return;
}
While (! Feof (RFP ))
{
Fread (& length, sizeof (unsigned short), 1, RFP );
Src = (unsigned char *) malloc (sizeof (unsigned char) * length );
DST = (unsigned char *) malloc (sizeof (unsigned char) * length );
If (fread (SRC, sizeof (unsigned char), length, RFP) = length)
{
Fwrite (DST, sizeof (unsigned char), length, WFP );
}
Free (SRC );
Free (DST );
}
Fclose (WFP );
Fclose (RFP );
}
5. Compile the SDK to obtain the corresponding DLL file;
6. Copy the DLL file to the same directory as the execution file, and then use the following statement:
Hinstance hdll; // DLL handle
Hdll = loadlibrary ("DLL. dll" L );
If (null = hdll)
{
MessageBox ("DLL loading failed ");
}
// Lpfun addfun; // function pointer
Lpfun ptransfor = (lpfun) getprocaddress (hdll, "transfor ");
If (null = ptransfor)
{
MessageBox ("failed to search for functions in DLL ");
}
Ptransfor ("3.pcm"," 2.wav ");
Reprinted from: http://sniffer.onlyblog.com/blog2/zyjzyj2000/9977.html