Creation and use of non-MFC Dynamic Link Libraries

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.