这是我写的惨痛的调用程序,定义了两个文本框,都是定义为control,还有一个按钮。想要实现从第一个文本框输入参数,传入存储过程,经过处理后再把返回值从第二个文本框输出这样一个功能,犯了不少低级错误,希望哪位大侠给予指点,谢谢。void CExView::OnButton1()
{
// TODO: Add your control notification handler code here
typedef short(_cdecl *Connect)(char scaller);
HINSTANCE hinstDLL=NULL;
hinstDLL=LoadLibrary("ex1.dll");
if(hinstDLL)
{
CString str1;
short str2;
m_E1.GetWindowText(str1);
UpdateData(true);
//CString str;
Connect Proc;
Proc=(Connect)GetProcAddress(hinstDLL,"IF_MEMBER");
char iValue = Proc(str1);
m_E2.SetWindowText(str2);
UpdateData(false);
FreeLibrary(hinstDLL); }
else
{
Beep(999,1000);
AfxMessageBox("没找到dll");
}
}
××××××××××××××××××××××
这是所报的错误
××××××××××××××××××
D:\MyDLL\ex\exView.cpp(154) : error C2664: 'short (char)' : cannot convert parameter 1 from 'class CString' to 'char'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\MyDLL\ex\exView.cpp(154) : warning C4244: 'initializing' : conversion from 'short' to 'char', possible loss of data
D:\MyDLL\ex\exView.cpp(155) : error C2664: 'SetWindowTextA' : cannot convert parameter 1 from 'short' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.×××××××××××××××××××××××
这是和数据库中存储过程链接的dll文件代码
××××××××××××××××××××××
extern "C" _declspec(dllexport) short IF_MEMBER(char scaller )
//short IF_MEMBER(char* scaller ){
_CommandPtr m_pCommand;
_ConnectionPtr gADOConnection1;
HRESULT hr;
short ret;
char Caller[20];
//return 0;
memset(Caller,0,sizeof(Caller)); sprintf(Caller,"%s",scaller);
//
CONNDB; _ParameterPtr m_pPara01 = NULL;
_variant_t vt01(Caller);
_variant_t vt02;
try
{
hr=m_pCommand.CreateInstance("ADODB.Command");
if(SUCCEEDED(hr))
{
m_pCommand->CommandText="VIS_VALIDUSER";
m_pCommand->CommandType = adCmdStoredProc;
m_pPara01 = m_pCommand->CreateParameter("CallerNUM", adBSTR, adParamInput,sizeof(Caller), vt01);
m_pCommand->Parameters->Append(m_pPara01);
m_pPara01->Value = vt01;
m_pCommand->ActiveConnection = gADOConnection1;
m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
// ret = (short)m_pCommand->Parameters->Item[(_variant_t)5L]->Value;
if(ret==10998||ret==10999)
return ret;
// strcpy(ret,(_bstr_t)m_pCommand->Parameters->Item[(_variant_t)4L]->Value);
}
else{
CLOSEDB
}
}
catch(_com_error e)///捕捉异常
{
CLOSEDB
}
CLOSEDB
return ret;}
{
// TODO: Add your control notification handler code here
typedef short(_cdecl *Connect)(char scaller);
HINSTANCE hinstDLL=NULL;
hinstDLL=LoadLibrary("ex1.dll");
if(hinstDLL)
{
CString str1;
short str2;
m_E1.GetWindowText(str1);
UpdateData(true);
//CString str;
Connect Proc;
Proc=(Connect)GetProcAddress(hinstDLL,"IF_MEMBER");
char iValue = Proc(str1);
m_E2.SetWindowText(str2);
UpdateData(false);
FreeLibrary(hinstDLL); }
else
{
Beep(999,1000);
AfxMessageBox("没找到dll");
}
}
××××××××××××××××××××××
这是所报的错误
××××××××××××××××××
D:\MyDLL\ex\exView.cpp(154) : error C2664: 'short (char)' : cannot convert parameter 1 from 'class CString' to 'char'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\MyDLL\ex\exView.cpp(154) : warning C4244: 'initializing' : conversion from 'short' to 'char', possible loss of data
D:\MyDLL\ex\exView.cpp(155) : error C2664: 'SetWindowTextA' : cannot convert parameter 1 from 'short' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.×××××××××××××××××××××××
这是和数据库中存储过程链接的dll文件代码
××××××××××××××××××××××
extern "C" _declspec(dllexport) short IF_MEMBER(char scaller )
//short IF_MEMBER(char* scaller ){
_CommandPtr m_pCommand;
_ConnectionPtr gADOConnection1;
HRESULT hr;
short ret;
char Caller[20];
//return 0;
memset(Caller,0,sizeof(Caller)); sprintf(Caller,"%s",scaller);
//
CONNDB; _ParameterPtr m_pPara01 = NULL;
_variant_t vt01(Caller);
_variant_t vt02;
try
{
hr=m_pCommand.CreateInstance("ADODB.Command");
if(SUCCEEDED(hr))
{
m_pCommand->CommandText="VIS_VALIDUSER";
m_pCommand->CommandType = adCmdStoredProc;
m_pPara01 = m_pCommand->CreateParameter("CallerNUM", adBSTR, adParamInput,sizeof(Caller), vt01);
m_pCommand->Parameters->Append(m_pPara01);
m_pPara01->Value = vt01;
m_pCommand->ActiveConnection = gADOConnection1;
m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
// ret = (short)m_pCommand->Parameters->Item[(_variant_t)5L]->Value;
if(ret==10998||ret==10999)
return ret;
// strcpy(ret,(_bstr_t)m_pCommand->Parameters->Item[(_variant_t)4L]->Value);
}
else{
CLOSEDB
}
}
catch(_com_error e)///捕捉异常
{
CLOSEDB
}
CLOSEDB
return ret;}
解决方案 »
- 刚入职不要一个月就要离职的人伤不起啊……
- 获取登陆到系统的用户的一个问题
- 局域网中,UDP传输在断线又恢复后,对方收不到数据了.UDP应该是无连接的呀,怎么会这样呢?附代码.
- 五四大游行,用行动来抗日!!!
- 求助:消息传递能以有层次的结构的数据传递,如结构体?
- mediaplayer如何播放rm格式网络电台?
- 如何用已经存在数组中的像素值产生一新的BMP图片 急急急急急急!
- 如何删除vc里的那些垃圾文件
- vs2010+openv显示图片Debug运行成功而Release可以运行但不显示图片?
- InstallSheild怎么修改注册表,只要提示就有分
- 如何利用vc把数据输出到一个word文档中?
- 请教:MFC模块管理的问题
应该是typedef short(_cdecl *Connect)(char* scaller);m_E2.SetWindowText(str2);这里的str2声明为short而不是字符串,并且没有初始化就使用了