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