Hi;
I am having trouble with a DLL function that is available to my calling program. The function receives char * parameter and calls another function that lives inside of the the dll. For some reason, the internal function does not get called by the exported function inside the dll, or more correctly, the calling program stalls. Can anyone assist with this? Here is the code.
#include "stdafx.h"
#include "mfcdll.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "ctype.h"
#include "windows.h"
#include "winerror.h"
int intStrTrmLen(char *strSource, int intLength);
int strCaseLower(char *strDestination[ ],char *strSource [ ]);
int intStrConvert(char *strString,char *strNewString,int nLength);
char * strStrConvert(char *strString,char *strNewString,int nLength);
void rtrim( char * string, char * trim );
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CMfcdllApp, CWinApp)
//{{AFX_MSG_MAP(CMfcdllApp)
// 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()
CMfcdllApp::CMfcdllApp()
CMfcdllApp theApp;
#define DllImport extern "C" __declspec( dllimport )
#define DllExport extern "C" __declspec( dllexport )
int intStrTrmLen(char *strSource, int intLength)
/*char *strSource;
int intLength;*/
{
/*AFX_MANAGE_STATE(AfxGetStaticModuleState());*/
int intCharIndex;
for(intCharIndex=intLength - 1;
intCharIndex > 0 && !isgraph(strSource[intCharIndex]);
intCharIndex--);
return(intCharIndex + 1);
/* return TRUE;*/
}
int strCaseLower(char strDestination[ ],char strSource [ ])
/*char *strDestination;
char *strSource;*/
{
int intLen, intIndex;
intLen = strlen(reinterpret_cast<const char *>(strSource)) + 1;
for (intIndex=0; intIndex < intLen; intIndex++)
{
strDestination[intIndex] = tolower(strSource[intIndex]);
}
return(intLen - 1);
/*return TRUE;*/
}
/* Convert a Quick string to a C string */
int intStrConvert(char *strString,char *strNewString,int nLength)
/*char *strString;
char *strNewString;
int nLength;*/
{
int intStrLen;
intStrLen = intStrTrmLen(strString,nLength);
strncpy(strNewString,strString,intStrLen);
strNewString[intStrLen] = '\0';
return (strlen(strNewString));
/*return TRUE;*/
}
/* Convert a Quick string to a C string */
char * strStrConvert(char *strString,char *strNewString,int nLength)
/*char *strString;
char *strNewString;
int nLength;*/
{
int intStrLen;
intStrLen = intStrTrmLen(strString,nLength);
strncpy(strNewString,strString,intStrLen);
strNewString[intStrLen] = '\0';
return (strNewString);
}
void rtrim( char * string, char * trim )
{
int i;
for( i = strlen (string) - 1; i >= 0
&& strchr ( trim, string ) != NULL; i-- )
// replace the string terminator:
string = '\0';
}
DllExport TestGetEnvVar(char * parm1)
{
char * parm2="";
int iparm1=strlen(parm1);
char * lparm1 = (char *)iparm1;
//Program stalls when it tries to call the strStrConvert internal function.
strStrConvert(parm1,parm2,iparm1);
rtrim(parm1,(char *)"\0");
char * enval2 = getenv(parm1);
strcpy(parm1,enval2);
return;
}
Here's the .def file I have.
; mfcdll.def : Declares the module parameters for the DLL.
LIBRARY "mfcdll"
DESCRIPTION 'mfcdll Windows Dynamic Link Library'
EXPORTS
ExportedFunction
TestGetEnvVar
intStrTrmLen
intStrTrmLen
strCaseLower
intStrConvert
strStrConvert
rtrim
/*NOTE:
These functions:
intStrTrmLen
intStrTrmLen
strCaseLower
intStrConvert
strStrConvert
rtrim
do NOT need to be exposed to the calling program.
*/
Any help would be appreciated.
thanks
jbsys
I am having trouble with a DLL function that is available to my calling program. The function receives char * parameter and calls another function that lives inside of the the dll. For some reason, the internal function does not get called by the exported function inside the dll, or more correctly, the calling program stalls. Can anyone assist with this? Here is the code.
#include "stdafx.h"
#include "mfcdll.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "ctype.h"
#include "windows.h"
#include "winerror.h"
int intStrTrmLen(char *strSource, int intLength);
int strCaseLower(char *strDestination[ ],char *strSource [ ]);
int intStrConvert(char *strString,char *strNewString,int nLength);
char * strStrConvert(char *strString,char *strNewString,int nLength);
void rtrim( char * string, char * trim );
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CMfcdllApp, CWinApp)
//{{AFX_MSG_MAP(CMfcdllApp)
// 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()
CMfcdllApp::CMfcdllApp()
CMfcdllApp theApp;
#define DllImport extern "C" __declspec( dllimport )
#define DllExport extern "C" __declspec( dllexport )
int intStrTrmLen(char *strSource, int intLength)
/*char *strSource;
int intLength;*/
{
/*AFX_MANAGE_STATE(AfxGetStaticModuleState());*/
int intCharIndex;
for(intCharIndex=intLength - 1;
intCharIndex > 0 && !isgraph(strSource[intCharIndex]);
intCharIndex--);
return(intCharIndex + 1);
/* return TRUE;*/
}
int strCaseLower(char strDestination[ ],char strSource [ ])
/*char *strDestination;
char *strSource;*/
{
int intLen, intIndex;
intLen = strlen(reinterpret_cast<const char *>(strSource)) + 1;
for (intIndex=0; intIndex < intLen; intIndex++)
{
strDestination[intIndex] = tolower(strSource[intIndex]);
}
return(intLen - 1);
/*return TRUE;*/
}
/* Convert a Quick string to a C string */
int intStrConvert(char *strString,char *strNewString,int nLength)
/*char *strString;
char *strNewString;
int nLength;*/
{
int intStrLen;
intStrLen = intStrTrmLen(strString,nLength);
strncpy(strNewString,strString,intStrLen);
strNewString[intStrLen] = '\0';
return (strlen(strNewString));
/*return TRUE;*/
}
/* Convert a Quick string to a C string */
char * strStrConvert(char *strString,char *strNewString,int nLength)
/*char *strString;
char *strNewString;
int nLength;*/
{
int intStrLen;
intStrLen = intStrTrmLen(strString,nLength);
strncpy(strNewString,strString,intStrLen);
strNewString[intStrLen] = '\0';
return (strNewString);
}
void rtrim( char * string, char * trim )
{
int i;
for( i = strlen (string) - 1; i >= 0
&& strchr ( trim, string ) != NULL; i-- )
// replace the string terminator:
string = '\0';
}
DllExport TestGetEnvVar(char * parm1)
{
char * parm2="";
int iparm1=strlen(parm1);
char * lparm1 = (char *)iparm1;
//Program stalls when it tries to call the strStrConvert internal function.
strStrConvert(parm1,parm2,iparm1);
rtrim(parm1,(char *)"\0");
char * enval2 = getenv(parm1);
strcpy(parm1,enval2);
return;
}
Here's the .def file I have.
; mfcdll.def : Declares the module parameters for the DLL.
LIBRARY "mfcdll"
DESCRIPTION 'mfcdll Windows Dynamic Link Library'
EXPORTS
ExportedFunction
TestGetEnvVar
intStrTrmLen
intStrTrmLen
strCaseLower
intStrConvert
strStrConvert
rtrim
/*NOTE:
These functions:
intStrTrmLen
intStrTrmLen
strCaseLower
intStrConvert
strStrConvert
rtrim
do NOT need to be exposed to the calling program.
*/
Any help would be appreciated.
thanks
jbsys