虎式模型轮子上色:C++ 高手请进!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 02:23:28
这是个控件的例子,通过包装 .dll 动态链接库实现对 dll 中方法的调用
文件如下:

Print_Invoice.ocx 控件调用 PTR_Statement_NT.dll 中的方法
其中 PTR_Statement_NT.dll 中大约有30个方法,而 Print_Invoice.ocx
只对其中的10个方法进行了调用,如果我要增加调用的方法,如何在控件中添加方法?以下是我手动添加的方法,可是老是报错:

//所在文件:Print_InvoiceCtl.cpp

BEGIN_DISPATCH_MAP(CPrint_InvoiceCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CPrint_InvoiceCtrl)

//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CPrint_InvoiceCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CPrint_InvoiceCtrl, "OpenDevice", OpenDevice, VT_I4, VTS_NONE)
DISP_FUNCTION(CPrint_InvoiceCtrl, "CloseDevice", CloseDevice, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CPrint_InvoiceCtrl, "GetStatus", GetStatus, VT_I4, VTS_NONE)
DISP_FUNCTION(CPrint_InvoiceCtrl, "PrintString", PrintString, VT_I4, VTS_BSTR)
DISP_FUNCTION(CPrint_InvoiceCtrl, "PrintFile", PrintFile, VT_I4, VTS_BSTR)
DISP_FUNCTION(CPrint_InvoiceCtrl, "CutPaper", CutPaper, VT_I4, VTS_NONE)
DISP_FUNCTION(CPrint_InvoiceCtrl, "MoveLeft", MoveLeft, VT_EMPTY, VTS_I4)
DISP_FUNCTION(CPrint_InvoiceCtrl, "MoveRight", MoveRight, VT_EMPTY, VTS_I4)
DISP_FUNCTION(CPrint_InvoiceCtrl, "MoveUp", MoveUp, VT_EMPTY, VTS_I4)
DISP_FUNCTION(CPrint_InvoiceCtrl, "MoveDown", MoveDown, VT_EMPTY, VTS_I4)

//手动添加的代码,也是报错的地方
DISP_FUNCTION(CPrint_InvoiceCtrl, "SetPrintLPI", SetPrintLPI, VT_I4, VTS_I4)

END_DISPATCH_MAP()

//新添加的方法
int CPrint_InvoiceCtrl::SetPrintLPI( int iLinespace )
{
int ret = -100;

typedef int( *DllFun )( int );

DllFun CtrlSetPrintLPI;

if( m_hDll != NULL )
{
CtrlSetPrintLPI = (DllFun)GetProcAddress(m_hDll, "SetPrintLPI");
if( CtrlSetPrintLPI != NULL)
{
ret = CtrlSetPrintLPI( iLinespace );
}
}
return ret;
}

//所在文件:Print_InvioceCtl.h
// Dispatch maps
//{{AFX_DISPATCH(CPrint_InvoiceCtrl)
afx_msg long SetPrintLPI(long iLinespace);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()

HINSTANCE m_hDll;
afx_msg void AboutBox();
afx_msg int OpenDevice();
afx_msg void CloseDevice();
afx_msg int GetStatus();
afx_msg int PrintString( char * );
afx_msg int PrintFile( char * );
afx_msg int CutPaper();
afx_msg void MoveLeft( int );
afx_msg void MoveRight( int );
afx_msg void MoveUp( int );
afx_msg void MoveDown( int );
//手动添加的代码:
afx_msg int SetPrintLPI( int );

//所报的错误如下:

D:\ZControl\NP325\Print_Invoice\Print_InvoiceCtl.cpp(49) : error C2440: 'type cast' : cannot convert from '' to 'void (__thiscall CPrint_InvoiceCtrl::*)(void)'
None of the functions with this name in scope match the target type

请各位大虾帮忙!!!!!!!!!问题及时解决定再加30分!!!!

int CPrint_InvoiceCtrl::SetPrintLPI( int iLinespace )

将返回的 int 改为 void

问题太长了