dll文件的调用有关问题,看了好久了
dll文件的调用问题,看了好久了
求助dll的调用问题,代码如下:
#include "stdafx.h"
#include "windows.h"
#include<iostream>
using namespace std;
typedef BOOL (__stdcall*pCntCon)(WORD CntMode,WORD ComPort,WORD TelNum[],WORD RESCode1[],WORD RESCode2[], WORD ConTmr[], WORD *ErrCode);
typedef BOOL(__stdcall*pDisCon)(WORD *ErrCode);
typedef BOOL (__stdcall*pMetsSetStatus)(WORD MetOpt, WORD MetSetSts, WORD MetPwr,
WORD Group, DWORD MetNum, DWORD RlyNum[],
WORD *MetSts, WORD *ErrCode);
WORD a1= (WORD)10; WORD a4 = (WORD)11;
void getConnect()
{
int a=0;
unsigned long b[6]={0};WORD key2[10]={'y','o','u','n','g','_','k','i','n','g'};
WORD time[7]={0};WORD a2=0x0001; WORD *k2=&a2;WORD c[20]={0};WORD key[10]={'y','o','u','n','g','_','k','i','n','g'};
HMODULE hModule;
pCntCon CntCon ;
hModule=LoadLibrary(TEXT("KSDLL.dll"));//加载动态链接库dll文件;
CntCon= (pCntCon)GetProcAddress(hModule,"CntCon");
a=CntCon(1,1,c,key,key2,time,k2);
cout<<a<<endl;
cout<<a<<*k2;
FreeLibrary(hModule);//卸载dll文件;
}
void turnOn()
{
int a3=0;
WORD *k3=&a4;
WORD *k1=&a1;
HMODULE hModule;
pMetsSetStatus MetsSetStatus ;
hModule=LoadLibrary(TEXT("KSDLL.dll"));//加载动态链接库dll文件;
MetsSetStatus=(pMetsSetStatus)GetProcAddress(hModule,"MetsSetStatus");
if(MetsSetStatus!=NULL) cout<<endl<<1234<<endl;
if(k1==NULL||k3==NULL) cout<<endl<<4321<<endl;
a3=MetsSetStatus(128,128,0,0,5555,0,k1,k3);//问题处在这句,我有哪里不对吗?前面一个函数调用是没有问题的,为什么这个有问题啊
FreeLibrary(hModule);//卸载dll文件;
}
void main(void)
{
getConnect();//这个还是调用是没有任何问题的。
turnOn();//这个函数调用就有问题了
system("pause");
}
报错如下:testdll.exe 中的 0x100088ec 处最可能的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突 (VS调试中冒出这样的错误,改了1天多时间了。)
求助dll的调用问题,代码如下:
#include "stdafx.h"
#include "windows.h"
#include<iostream>
using namespace std;
typedef BOOL (__stdcall*pCntCon)(WORD CntMode,WORD ComPort,WORD TelNum[],WORD RESCode1[],WORD RESCode2[], WORD ConTmr[], WORD *ErrCode);
typedef BOOL(__stdcall*pDisCon)(WORD *ErrCode);
typedef BOOL (__stdcall*pMetsSetStatus)(WORD MetOpt, WORD MetSetSts, WORD MetPwr,
WORD Group, DWORD MetNum, DWORD RlyNum[],
WORD *MetSts, WORD *ErrCode);
WORD a1= (WORD)10; WORD a4 = (WORD)11;
void getConnect()
{
int a=0;
unsigned long b[6]={0};WORD key2[10]={'y','o','u','n','g','_','k','i','n','g'};
WORD time[7]={0};WORD a2=0x0001; WORD *k2=&a2;WORD c[20]={0};WORD key[10]={'y','o','u','n','g','_','k','i','n','g'};
HMODULE hModule;
pCntCon CntCon ;
hModule=LoadLibrary(TEXT("KSDLL.dll"));//加载动态链接库dll文件;
CntCon= (pCntCon)GetProcAddress(hModule,"CntCon");
a=CntCon(1,1,c,key,key2,time,k2);
cout<<a<<endl;
cout<<a<<*k2;
FreeLibrary(hModule);//卸载dll文件;
}
void turnOn()
{
int a3=0;
WORD *k3=&a4;
WORD *k1=&a1;
HMODULE hModule;
pMetsSetStatus MetsSetStatus ;
hModule=LoadLibrary(TEXT("KSDLL.dll"));//加载动态链接库dll文件;
MetsSetStatus=(pMetsSetStatus)GetProcAddress(hModule,"MetsSetStatus");
if(MetsSetStatus!=NULL) cout<<endl<<1234<<endl;
if(k1==NULL||k3==NULL) cout<<endl<<4321<<endl;
a3=MetsSetStatus(128,128,0,0,5555,0,k1,k3);//问题处在这句,我有哪里不对吗?前面一个函数调用是没有问题的,为什么这个有问题啊
FreeLibrary(hModule);//卸载dll文件;
}
void main(void)
{
getConnect();//这个还是调用是没有任何问题的。
turnOn();//这个函数调用就有问题了
system("pause");
}
报错如下:testdll.exe 中的 0x100088ec 处最可能的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突 (VS调试中冒出这样的错误,改了1天多时间了。)
相关解决方案