
call another DLL from within a C++ DLL
I have written a DLL in C++ that is accessed through a VB basic
program. The DLL calls another C++ dll that is passed a typedef
structure, if i set a certain typedef structure variable the program
crashes, also it nevers calls the callback function. I am new at this
and need some help. Below is a copy of the code.
// tcn2gen.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "tcn2gen.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TRUE 1
#define FALSE 0
#define DLLEXPORT __declspec( dllexport )
/////////////////////////////////////////////////////////////////////////////
// CTcn2genApp
BEGIN_MESSAGE_MAP(CTcn2genApp, CWinApp)
//{{AFX_MSG_MAP(CTcn2genApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTcn2genApp construction
CTcn2genApp::CTcn2genApp()
{
AfxMessageBox("Starting DLL");
// TODO: add construction code here,
// Place all significant initialization in InitInstance
Quote:
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CTcn2genApp object
CTcn2genApp theApp;
int DLLEXPORT WINAPI ReturnPosValue(int *iValue)
{
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
//AfxMessageBox("ReturnPosValue Entered");
if (iValue > 0 ) {
return (*iValue);
}
else ( iValue <= 0 ); {
// AfxMessageBox("Invalid Number - less than Zero!");
return (0);
}
Quote:
}
// THIS IS THE FUNCTION THAT IS BEING CALLED FROM
VB------------------------
int DLLEXPORT WINAPI CallGenCri()
{
// UpdateData();
GENCRI_CONTROL_BLOCK *GCB = new GENCRI_CONTROL_BLOCK;
/*GCB->wCallNo = m_CallNo;
GCB->lpszDBFPath = m_DataPath.GetBuffer(0);
GCB->lpszUserID = m_UserID.GetBuffer(0) ;
GCB->lpszRCXFile = m_MBAFile.GetBuffer(0);
GCB->pCallBackFunc = Fn ;
GCB->FileNM = m_FileNM.GetBuffer(0) ;
GCB->BorrowerNo = m_BorNo.GetBuffer(0) ;*/
GCB->wCallNo = 0; // When i set this var. the program crashes
GCB->lpszDBFPath = "c:\\genesis\\data\\";
GCB->lpszUserID = "John" ;
GCB->lpszRCXFile = "";
GCB->pCallBackFunc = Fn ;
GCB->FileNM = "00000190" ;
GCB->BorrowerNo = "01" ;
GenCRI(GCB);
return(GCB->wStatus);
Quote:
}
void CALLBACK EXPORT Fn(WORD Status,
LPSTR lpszRefNo
)
{
AfxMessageBox("CallBack");
if (Status)
{
//AfxGetMainWnd()->PostMessage(GENCRIFAILED, (WPARAM)Status,0L);
AfxMessageBox("GenCRIOK : Return From GenCRI Successfully NO");
}
else
{
//AfxGetMainWnd()->PostMessage(GENCRIOK, (WPARAM)Status,0L);
AfxMessageBox("GenCRIOK : Return From GenCRI Successfully");
};
Quote:
};
LRESULT GenCRIOK(WPARAM WParam, LPARAM LParam)
{
AfxMessageBox("GenCRIOK : Return From GenCRI Successfully");
return 0 ;
Quote:
};
LRESULT GenCRIFailed(WPARAM WParam, LPARAM LParam)
{
switch (WParam)
{
case INVALID_CALL_NO:
AfxMessageBox("GenCRIFailed : Invalid Call No Passed to GenCRI.");
break;
case F1003_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : GenCRI Can Not Open Database !");
break;
case GENCRI_RECORD_NOT_FOUND:
AfxMessageBox("Record Not Found");
break;
case GENCRI_ERR_CREATING_CRI_FILE:
AfxMessageBox("GenCRIFailed : .CRI File Can't Be Created.");
break;
case TL_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : TrakLoan.DBF Can't be Opened");
break;
case VOE_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : VOE.DBF Can't be Opened");
break;
case LIAB_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : LIAB.DBF Can't be Opened");
break;
case PROP_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : VOM.DBF Can't be Opened");
break;
case PROPID_NOT_FOUND:
AfxMessageBox("GenCRIFailed : PropId Can't be Located in PROP.DBF");
break;
case RCX_FILE_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : Received File Can't Be Opened");
break;
case MBNA_SIGNATURE_NOT_FOUND:
AfxMessageBox("GenCRIFailed : Start of MBNA format data not found
!");
break;
case REPORT_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : REPORT.DBF can not be opened !");
break;
case ERORR_WRITTING_REPORT:
AfxMessageBox("GenCRIFailed : Error while writing REPORT.DBF !");
break;
case SYSNUM_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : SYSNUM.DBF not found !");
break;
case REQUEST_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : REQUEST.DBF not found !");
break;
case ERORR_WRITTING_REQUEST:
AfxMessageBox("GenCRIFailed : Error while writing REQUEST.DBF !");
break;
case ERROR_INITILIZING_REQUEST:
AfxMessageBox("GenCRIFailed : Error while writing REQUEST.DBF !");
break;
case REFNO_NOT_IN_REQUEST:
AfxMessageBox("GenCRIFailed : Reference number not found in
REQUEST.DBF !");
break;
case REFNO_NOT_IN_REPORT:
AfxMessageBox("GenCRIFailed : Reference number not found in
REPORT.DBF !");
break;
case MASTER_OPEN_ERROR:
AfxMessageBox("GenCRIFailed : Can not open MASTER.DBF !");
break;
case FILENM_NOT_FOUND_IN_F1003:
AfxMessageBox("GenCRIFailed : Record not found in F1003.DBF !");
break;
case INVALID_USER_ID:
AfxMessageBox("GenCRIFailed : Genesis UserId is Blank !");
break;
case RECORD_NOT_FOUND_IN_TL:
AfxMessageBox("GenCRIFailed : Record not found in TrakLoan.DBF !");
break;
case BLANK_FILENM:
AfxMessageBox("GenCRIFailed : Genesis Filenm is Blank !");
break;
case INVALID_BORNO:
AfxMessageBox("GenCRIFailed : Genesis BorrowerNo is Blank !");
break;
case INVALID_RECNO:
AfxMessageBox("GenCRIFailed : Internal Error : Invalid Record No !");
break;
case GENCRI_ABORTED:
AfxMessageBox("GenCRIFailed : GENCRI Aborted !");
break;
case REPOSITORY_CODE_NOT_VALID :
AfxMessageBox("GenCRIFailed : Repository Code Not Valid While
Importing Score Information !");
break;
case MEMORY_ALLOCATION_ERROR :
AfxMessageBox("GenCRIFailed : Memory Allocation Error While
Importing Credit Report !");
break;
default:
AfxMessageBox("GenCRIFailed : Unknown Error !");
break;
};
return 0 ;
Quote:
};
header file following
// tcn2gen.h : main header file for the TCN2GEN DLL
//
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CTcn2genApp
// See tcn2gen.cpp for the implementation of this class
//
#define GENCRI_SUCCESS 0
#define INVALID_CALL_NO 1
#define F1003_OPEN_ERROR 2
#define GENCRI_RECORD_NOT_FOUND 3
#define GENCRI_ERR_CREATING_CRI_FILE 4
#define TL_OPEN_ERROR 5
#define VOE_OPEN_ERROR 7
#define LIAB_OPEN_ERROR 8 // Either LIAB or AUTO open Error
#define PROP_OPEN_ERROR 9 // Either PROP or VOM open Error
#define PROPID_NOT_FOUND 10 // PropertyID in VOM can not be found in
PROP
#define RCX_FILE_OPEN_ERROR 11 // Error Openning the file received
from Credit Company
#define MBNA_SIGNATURE_NOT_FOUND 12 // Chr(12)+Chr(19) in RCX File not
Found
#define REPORT_OPEN_ERROR 13 // Error Openning REPORT.DBF
#define ERORR_WRITTING_REPORT 14 // Error while attempting to append a
record to REPORT.DBF
#define SYSNUM_OPEN_ERROR 15 // Error Openning SysNum
#define REQUEST_OPEN_ERROR 16 // Error Openning REQUEST.DBF
#define ERORR_WRITTING_REQUEST 17 // Error while attempting to append
a record to REQUEST.DBF
#define ERROR_INITILIZING_REQUEST 18 // Error in either Openning or
writing request.dbf
#define REFNO_NOT_IN_REQUEST 19 // Seek failed finding RefNo in
REQUEST.DBF
#define REFNO_NOT_IN_REPORT 20 // Seek failed finding RefNo in
REPORT.DBF
#define MASTER_OPEN_ERROR 21 //
#define FILENM_NOT_FOUND_IN_F1003 22 // The filenm extracted from
MASTER.DBF was not found in F1003.DBF
#define INVALID_USER_ID 23 // User Id is Blank or empty
#define RECORD_NOT_FOUND_IN_TL 24 // FileNM can not be found in TL
#define INVALID_RECNO 25 // Record No is zero
#define BLANK_FILENM 26 // F1003 or MASTER FileNM is Blank
#define GENCRI_ABORTED 27 // User Pressed ESC while in the browser
#define INVALID_BORNO 28 // Genesis BorNo is Blank
#define REPOSITORY_CODE_NOT_VALID 29 // When checking SC fields
repository code was not valid
#define MEMORY_ALLOCATION_ERROR 30 // Memory Allocation Error in
Function call 4 ONLY
#define CREDIT_REPORT_TOO_LARGE 31 // Credit Report File Is Bigger
than 1MB
#define ERROR_READING_CREDIT_REPORT 32 // Number of bytes read is
less than Credit File Size (ONLY in 4)
#define GENCRIOK WM_USER+1
#define GENCRIFAILED WM_USER+2
typedef struct _GENCRI_CONTROL_BLOCK {
WORD wCallNo; //IN Function Call No
// 1 :
// 2 :
// 3 :
// 4 :
// 5 :
LPSTR lpszDBFPath; //IN Path to Genesis Databases
LPSTR lpszUserID; //IN Genesis User ID
LPSTR FileNM; //IN FileNM
LPSTR BorrowerNo; //IN Borrower/CoBorrower
LPSTR lpszRCXFile; //IN Received File Name (from Credit
Company)
LPSTR lpszCrdtRptFile; //IN Received Credit Report
LPSTR lpszRefNo; //OUT Reference Number
WORD wStatus; //OUT Status of operation
void (CALLBACK *pCallBackFunc)(WORD Status, LPSTR lpszRefNo);
Quote:
} GENCRI_CONTROL_BLOCK;
void CALLBACK /*AFX_EXPORT*/ Fn(WORD Status, LPSTR lpszRefNo);
extern void WINAPI GenCRI(GENCRI_CONTROL_BLOCK* GCB);
class CTcn2genApp : public CWinApp
{
public:
CTcn2genApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTcn2genApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTcn2genApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
Quote:
};
/////////////////////////////////////////////////////////////////////////////
thanks,