I'm using Visual Studio 2005 on Windows. I was supplied a third party dll that I need to call from an MFC DLL that I'm creating.
I have a couple of questions.
1. General Question
The third party dll came with the dll named BB-CLOGP.DLL, a header file named clogp-dll.h and a folder named CLog P Data.
Here's how I set the project up:
Added clogp-dll.h in my project's main directory then added BB-CLOGP.DLL and the CLog P Data folder to the Debug folder where my dll is created when I compile the project. Does this sound correct?
2. Specific Errors
Here's the header file that came with the project:
Code:
// DH-20000401 moved RETURN_HANDLE define here
// DH-20000323 updated struct field sizes
// DH-19991005 initial version as per Kam Chana's specifications
// define this if verbose results desired, otherwise only the calculated
// value itself will be available to the calling function "CALCLOGP" which is imported around line 11 of my code
// struct for ClogP results
typedef struct {
char Class[10];
char Type[6];
char Description[40];
char Comment[10];
float Value;
} LogPContribution;
// struct for CMR results
typedef struct {
char flag[1];
char atomType[3];
float atomValue;
int atomCount;
char bondType[18];
float bondValue;
int bondCount;
} CMRContribution;
Here's my code that tries to call the dll. Specifically, I'm trying to
call the function CALCLOGP:
Code:
#include "stdafx.h" // Standard MFC libraries
#include "cfx.h" // CFX Custom Tag API
#include "clogp-dll.h" // External CLogP DLL Header File
// macros
#define IMPORT extern "C" __declspec(dllimport)
#define LINE_LIMIT 2048
// import DLL functions
typedef long (CALCLOGP)(const char*, float*, long*, HANDLE*);
typedef long (CALCCMR)(const char*, float*);
typedef long (CALCXMR)(const char*, float*);
typedef long (CALCMGVOL)(const char*, float*);
typedef long (MOL_FILE_IMPORT) (char* inputF, char* outputF);
typedef double (CLOGP_VIA_MOL) (char* myMol);
static CALCLOGP* calcLogP = NULL;
static CALCCMR* calcCMR = NULL;
static CALCXMR* calcXMR = NULL;
static CALCMGVOL* calcMgVol = NULL;
static MOL_FILE_IMPORT* mol_file_import;
static CLOGP_VIA_MOL* clogp_via_mol;
static HINSTANCE hinstCLogP = NULL;
static HINSTANCE hinstCopy = NULL;
void ProcessTagRequest( CCFXRequest* pRequest )
{
try
{
// Retrieve attributes passed to the tag
// For example:
// LPCSTR lpszColor = pRequest->GetAttribute("COLOR") ;
//Complete the import of the dll routines
hinstCLogP = LoadLibrary("bb-clogp.dll");
hinstCopy = hinstCopy;
calcLogP = (CALCLOGP *) GetProcAddress(hinstCLogP, "calcLogP");
calcCMR = (CALCCMR *) GetProcAddress(hinstCLogP, "calcCMR");
calcXMR = (CALCXMR *) GetProcAddress(hinstCLogP, "calcXMR");
calcMgVol = (CALCMGVOL *) GetProcAddress(hinstCLogP, "calcMgVol");
mol_file_import = (MOL_FILE_IMPORT *) GetProcAddress(hinstCLogP, "mol_file_import");
clogp_via_mol = (CLOGP_VIA_MOL *) GetProcAddress(hinstCLogP, "clogp_via_mol");
//Call the function to get the CLogP value
float pLogP;
long err;
long pNumContrb;
long smiles;
// Note: These MUST be GlobalFree( ) 'd after calls to calcLogP
LogPContribution** pClogPContrb, * pclogp;
pLogP = -99.99f;
pNumContrb = 0;
err = calcLogP(smiles, &pLogP, &pNumContrb, &pClogPContrb);
// smiles holds the smiles string of course.
// pLogP will have your value if err is less than 60.
// Later you must free as follows...
// GlobalFree(pClogPContrb);
// GlobalFree(pclogp);
// Write output back to the user here...
pRequest->Write( "Hello from CFX_HELLOWORLD!" ) ;
// Output optional debug info
if ( pRequest->Debug() )
{
pRequest->WriteDebug( "Debug info..." ) ;
}
}
// Catch Cold Fusion exceptions & re-raise them
catch( CCFXException* e )
{
pRequest->ReThrowException( e ) ;
}
// Catch ALL other exceptions and throw them as
// Cold Fusion exceptions (DO NOT REMOVE! --
// this prevents the server from crashing in
// case of an unexpected exception)
catch( ... )
{
pRequest->ThrowException(
"Error occurred in tag CFX_HELLOWORLD",
"Unexpected error occurred while processing tag." ) ;
}
}
When I try to compile, I get errors regarding the parameters in the function call to
err = calcLogP(smiles, &pLogP, &pNumContrb, &pClogPContrb); This is called around line 63
The specific errors I get are:
Code:
c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(70) : error C2664: 'CALCLOGP' : cannot convert parameter 4 from 'LogPContribution ***__w64 ' to 'HANDLE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(70) : error C2664: 'CALCLOGP' : cannot convert parameter 3 from 'float *__w64 ' to 'long *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(70) : error C2664: 'CALCLOGP' : cannot convert parameter 1 from 'long *__w64 ' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Generating Code...
Additionally, the instructions do not declare the variable in parameter 1 anywhere (smiles).
I'm assuming I can set it to a type of long
I've been struggling with this for awhile so help is greatly appreciated.