Wednesday, June 30, 2010

How to call DLL VB6 from C++

Found this code was very sample way

Assume that ur VB6 declare like this

Dll name : syBaseForMrr.dll
Project Name : syBase_dll
Class Name : syBaseCtrl
Function Name :
Public Function getLastTransaction() As String
BANK_MESSAGE = "ERROR"
PROCESS_NOW
getLastTransaction = BANK_MESSAGE
End Function


On .cpp file

- Declaration
#import "E:\\syBaseForMrr.dll"
using namespace syBase_dll;

- Calling code

int mesraRefund::sendMesraRefundRecovery()
{
HRESULT hresult;
CLSID clsid;
_syBaseCtrl *t;
_bstr_t bstrR;
::CoInitialize(NULL);
hresult=CLSIDFromProgID(OLESTR("syBase_dll.syBaseCtrl"), &clsid);
hresult= CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,
__uuidof(_syBaseCtrl),(LPVOID*) &t);
if(hresult == S_OK)
{
bstrR = t->getLastTransaction();
AfxMessageBox((char*)bstrR);
}
return 0;
}

No comments: