-
April 3rd, 2005, 08:53 PM
#1
Error when VC++ program calls C dll
Hi, I am getting this error when I make the dll function call (ezcch) from my test VC++ program...
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
Do I need to change my func declaration in my C or C++ programs? I know the function variables are passed differently between C and C++. But I do not remember the specifics.
/ dlltester.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <windows.h>
#include <string>
#include <iostream>
typedef void (CALLBACK* EZCCHFUNC)(const char *, const char*, char *, char*,
char*, char*, char*, char*);
int _tmain(int argc, _TCHAR* argv[])
{
int rc = 0;
char commandInput[600] = "";
char status[2048] = "";
char answer[2048] = "";
char help[1024] = "";
char statwin[] = "STATWIN";
HINSTANCE hh = LoadLibrary("C:/EZTax Projects/ezcchbridge/Debug/ezcchbridge.dll");
if (hh != NULL) {
EZCCHFUNC ezcch = (EZCCHFUNC) GetProcAddress(hh, "ezcchproc");
ezcch(commandInput, statwin, status, answer, help, 0, 0, 0);
FreeLibrary(hh);
}
else {
rc = GetLastError();
}
return 0;
}
//************C DLL code***************
//ezcchbridge.c
#define EZCCH __declspec(dllexport)
#include <stdio.h>
EZCCH void ezcchproc(const char *command, // 1
const char* mode, // 2
char* status, // 3
char* answer, // 4
char* help, // 5
char* extra3, // 6
char* extra2 , // 7
char* extra1) // 8
{
printf("I'm in");
}
//ezcchbridge.def
LIBRARY ezcchbridge
EXPORTS
ezcchproc @2
-
April 4th, 2005, 02:44 AM
#2
Re: Error when VC++ program calls C dll
Your C dll is using a calling convention and your C++ app a different one. Check both project settings to see the actual values. Then, in your C++ application specify the calling convention when defining the function signature.
If youC dll is using the _cdecl convention than use:
Code:
typedef void (_cdecl *EZCCHFUNC)(const char *, const char*, char *, char*,
char*, char*, char*, char*);
Har Har
-
April 6th, 2005, 09:10 PM
#3
Re: Error when VC++ program calls C dll
That worked, thanks Padex
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|