C + + Encapsulation Library

Source: Internet
Author: User

1. New Project--WIN32 Project
Select the DLL, tick the empty project, click Finish.

2. This routine uses a CPP file, and a header file. Where the header file contains the function declaration, the CPP file implements the function declaration.

3. header file: SSLLib.h

#pragma once//avoid repeating Yi
#ifndef __ssllib_h//consistent with #pragma once, compatible settings
#define __ssllib_h

#ifndef __dll_exports
#define __dll_exports _declspec (dllimport)
#endif

declaring function interfaces
extern "C" __dll_exports int encodersakeyfile (const char * _strpemfilename, const char * _strdata, unsigned char * buffer , int length);
extern "C" __dll_exports int decodersakeyfile (const char * _strpemfilename, const char * _strdata, unsigned char * buffe r, int length);

#endif


SSLLIB.h Terminator

4. Create a file with the header to check the CPP file SSLLib.CPP

#include "SSLLib.h"//Include header file

function implementation
int encodersakeyfile (const char * _strpemfilename, const char * _strdata, unsigned char * buffer, int length) {
Function Implementation ...
}

int decodersakeyfile (const char * _strpemfilename, const char * _strdata, unsigned char * buffer, int length) {
Function Implementation ...
}

SSLLib.CPP Terminator

5. Using a library file in a C + + file
#include "SSLLib.h"//reference header file

6. In different Yi mode, reference static file
#ifdef _DEBUG
#pragma comment (lib, "... \\Debug\\SSLLib.lib ");
#else
#pragma comment (lib, "... \\Release\\SSLLib.lib ");
#endif

You can then use the library you just created directly in the project file.
C + + reference Terminator


7. C # Uses


Create a DLL folder in the C # project file to copy the DLL files and associated static library files into.

Property settings:
Copy to output directory: Copy if newer
Build Action: Content

C # Invocation Example:
[System.Runtime.InteropServices.DllImportAttribute ("Dll\\ssllib.dll", EntryPoint = "Encodersakeyfile")]
public static extern int Encodersakeyfile ([System.Runtime.InteropServices.InAttribute ()] [ System.Runtime.InteropServices.MarshalAsAttribute (SYSTEM.RUNTIME.INTEROPSERVICES.UNMANAGEDTYPE.LPSTR)] string _ Strpemfilename, Byte [] _strdata, byte [] buffer, int length);

It is important to note that C # Byte type default range 0-255, C + + Char default Type-128 ~ 127, so when C + + interface function declaration, corresponding to unsigned type unsigned Char








C + + Encapsulation Library

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.