次の C++
コードを作成して作成しましたwin 32 Dynamic link library
。
#include <windows.h>
#include <some.h>
unsigned char m_KSN[10];
unsigned char m_inintial_key[16];
unsigned char initial_key[16];
extern "C" __declspec(dllexport) unsigned char* OnDecryption(LPCTSTR stringKSN,
LPCTSTR BDK){
for( i=0;i<10;i++){
m_KSN[i]=asctohex(stringKSN[2*i],stringKSN[2*i+1]); }
for( i=0;i<16;i++){
m_inintial_key[i]=asctohex(BDK[2*i],BDK[2*i+1]);}
GetInitalKey(m_KSN, m_inintial_key, initial_key);
// GetInitialKey function written in `.lib` file. Data type of (Byte*a Byte* b Byte* c)
return initial_key;
}
私のC#
コードは次のとおりです。
static class DecryptionDll
{
public String BDK = "0111111119ABCDEFFEDCBA9877777777";
public String KSN = "62994900380000C00329";
internal static class UnsafeNativeMethods
{
const string _dllLocation = "finalTest.dll";
[DllImport(_dllLocation)]
public static extern byte OnDecryption(string ksn, String bdk);
}
}
ファイルを現在のディレクトリに置き、dll
次のコマンドで取得しました。
String path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.
GetExecutingAssembly().Location);
my debug
フォルダーが現在のパスであることを示しています。だから私はdll
そこに入れました。PInvoke
また、多くの投稿を受け取りましたが、状況を理解できませんでした。私を助けてください..
c++
で書かれたメソッドを呼び出すには、何を変更すればよいか、またはc#
コードをどのように変更すればよいか教えてくださいdll
。
編集が多くて大変申し訳ありません。接続が遅いために発生します