7,764
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include "Cipher.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
__declspec(dllexport) string __stdcall compress_wireless(string str)
{ int j,k,g,resend_buf[MAX_PACK_SIZE],wireless_buf[MAX_PACK_SIZE];
static string array[MAX_PACK_SIZE],compress_data1,compress_data2;
unsigned int compress_data;
for(unsigned int i=0;i<=str.length();i+=3){
g =i/3;
array[g]=str.substr(i,2);}
for(int h=0;h<=14;h++){
stringstream ss_1;
ss_1<<hex<<array[h];
ss_1>>wireless_buf[h];
ss_1.str("");
}
for(j=0;j<15;j++)
resend_buf[1+j]=wireless_buf[j];
for(j=0;j<14;j++){
compress_data=wireless_buf[j]*0x100+wireless_buf[j+1];
if((compress_data&0x8000)!=0)
compress_data=((compress_data/0x100)^0x89)*0x100+compress_data%0x100;
for(k=0;k<8;k++){
compress_data<<=1;
if((compress_data&0x8000)!=0)
compress_data=((compress_data/0x100)^0x89)*0x100+compress_data%0x100;
}
wireless_buf[j+1]=compress_data/0x100;
}
for(k=0;k<7;k++){
compress_data<<=1;
if((compress_data&0x8000)!=0)
compress_data=((compress_data/0x100)^0x89)*0x100+compress_data%0x100;
}
compress_data<<=1;
stringstream ss_2;
ss_2<<hex<<compress_data;
ss_2>>compress_data1;
compress_data2 = compress_data1.substr(0,2);
transform(compress_data2.begin(),compress_data2.end(),compress_data2.begin(),towupper);
return compress_data2;
}
#pragma once
#include "targetver.h"
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include<algorithm>
using namespace std;
#define WIN32_LEAN_AND_MEAN
#define MAX_PACK_SIZE 20
#ifdef CIPHER_EXPORTS
#define CIPHER_API __declspec(dllexport)
#else
#define CIPHER_API __declspec(dllimport)
#endif
// 此类是从 Cipher.dll 导出的
__declspec(dllexport) string __stdcall compress_wireless(string str);
LIBRARY Cipher
EXPORTS compress_wireless
Option Explicit
Private Declare Function compress_wireless Lib "C:\Users\Administrator\Desktop\Cipher\Debug\Cipher.dll" (ByVal p As String) As String
Private Sub Command1_Click()
Dim str As String
str = compress_wireless("80 66 0A 99 0B 28 0A 0D 0D 0D 0D 0D 0D 0D 00 ")
Text1..Text = str
End Sub
Private Sub Text1_Change()
End Sub
// 数据类型的定义:
static string array[MAX_PACK_SIZE],compress_data1,compress_data2;
// API的返回:
return compress_data2;
如果这“返回数据”都是有效的ASCII字符,
可以用Strconv( )函数把它从 Byte数组转换成字符串,再赋值给 TextBox控件。