Home > Software engineering >  The Run - Time Check Failure # 0 how to solve ah, for a long Time didn't solve.
The Run - Time Check Failure # 0 how to solve ah, for a long Time didn't solve.

Time:09-20

Have a program, it is my original program, running without problems, running is very good,

Later call other DLLS, h, lib upgrade, need to replace the old,

Assignment to paste the three files to folder, covering the old, the various functions of the corresponding modification is compatible with the new entrance parameters. After h,
Compile, but run a hint:
The Run - Time Check Failure # 0 The value of ESP was not properly saved across indicates a function call.
This is usually a result of calling a function declared with one calling convention with a function pointer declared with a company's calling convention.

I try to within the project, in addition to open a function, check all separate written using two DLL functions, prompt the error,
ABC. DLL, ABC. Lib, ABC. H this three files,
Call:
Void CTest: : TestFunction ()
{
Short sReturn;
SReturn=ABC_Function1 (value1, value2);
SReturn=ABC_Function2 (value1, value2);
}
Procedures performed the test functions, the prompt immediately above the error,

But also create a new project, I put the test function to copy and paste into, no problem, the function return value correctly, run perfect,
Use the same DLL, lib, h file,

Online said the __cdecl (Gd)/change __stdcall (/Gz), I've tried, not line, as well as prompt the error,
How to solve?
The MFC VS2008

Where is the set set up? Should not code problem,
If is code problem, can help on my test functions changed?
First thank you,

CodePudding user response:

Problems, make inspections and function is the function calling convention definition, statement are consistent

CodePudding user response:

//try
# ifdef __cplusplus
Extern "C" {
# endif

# include "XXX. H
"
# ifdef __cplusplus
}
#endif

CodePudding user response:

refer to the second floor zgl7903 response:
//try
# ifdef __cplusplus
Extern "C" {
# endif

# include "XXX. H
"
# ifdef __cplusplus
}
# endif


Try, still the same error prompt

CodePudding user response:

reference 1st floor schlafenhamster response:
is the function calling convention, check function definition, compliance statement


Function definitions, the statement is the same in the CPP jump right function definition, the view is the same,
Specially picked two minimum parameters function test, not define problems is not the same as the statement,

CodePudding user response:

For the two days there is no solution,

Now to a new project, redistribute the MFC to do it again, and then paste the code assignment in the past, with respect to OK,

Copy and paste the code to a new project, compile and run the normal, it seems not code issue,
Or accidentally met what VS Settings, or will not be covered in the case of open versus reference documents,

CodePudding user response:

It is good to solve!

CodePudding user response:

Estimate of the default calling convention and somebody else is your project of DLL, the DLL's header file inside should be calling conventions,

CodePudding user response:

Calling convention https://msdn.microsoft.com/zh-cn/magazine/9b372w95.aspx

CodePudding user response:

DLL export function name the things
Key words: vc + + DLL export functions
Often use VC6 Dependency check the name of the DLL export functions, can find the name of the DLL export functions are sometimes very different, the cause of different mostly and compile DLL when specified by the qualifier with the DLL export functions,
Vc + + to support two languages: C/C + +, this also is the root cause of the differences in the DLL export functions
We use VS2008 new DLL project, a project called "TestDLL"
The default source file suffix. CPP instead. C (C)
Enter the test code is as follows:
01 int _stdcall MyFunction (int iVariant)
02 {
03 return 0;
04}
In order to export the function above, we have the following several methods:
1. Using the traditional (. The module definition file (def)
A new suffix for. Def text file (here to build a TestDll. Def), the file content is:
The LIBRARY TestDll
EXPORTS
MyFunction
When the Link specified depends on input file:/DEF: "TestDll. DEF
"2. Visual c + + provides convenient way
Join before 01 done int __declspec (dllexport) keyword
Through the above two methods, we can export MyFunction function,
We use the Dependency check the exported functions:
The first method the exported functions as follows:
MyFunction
The second method the exported functions as follows:
_MyFunction @ 4
__stdcall can make the export function to add an underscore the names, followed a @ plus the number of bytes parameters, such as _MyFunction @ 4 parameters (int iVariant) is 4 bytes
__fastcall as __stdcall similar, but not in front of the underline, but a @, such as @ MyFunction @ 4
__cdecl is beginning the function name,
Summary: if you want to export the function in the C file, and don't let the compiler function name, def file is used to derive the function,
Let's take a look at c + + files
We use VS2008 new DLL project, a project called "TestDLL"
The default source file suffix for the CPP (namely c + + files),
Enter the test code is as follows:
01 int _stdcall MyFunction (int iVariant)
02 {
03 return 0;
04}
In order to export the function above, we have the following several methods:
3. Use the traditional (. The module definition file (def)
A new suffix for. Def text file (here to build a TestDll. Def), the file content is:
The LIBRARY TestDll
EXPORTS
MyFunction
When the Link specified depends on input file:/DEF: "TestDll. DEF
"4. Visual c + + provides convenient way
Join before 01 done int __declspec (dllexport) keyword
Through the above two methods, we can export MyFunction function,
We use the Dependency check the exported functions:
The first method the exported functions as follows:
MyFunction
The second method the exported functions as follows:
? MyFunction @ @ YGHH @ Z
Can see the second method to get the export function name is not what we want, and if used display method in exe MyFunction (LoadLibrary and GetProcAddress call) call will fail,
But with the import library (*. LIB) calls, the compiler automatically convert the function name, so there is no problem, always
Solve the problem of method is:
Using VC preprocessor directive to "# pragma" option to specify links,
As follows:
# pragma comment (would, "/EXPORT: MyFunction=? MyFunction @ @ YGHH @ Z ")
At this moment, you will find the exported function name in the table have we want MyFunction, but we found the original? MyFunction @ @ YGHH @ Z function is still there, then you can put the __declspec () modified to remove, you just need to pragma directive,
But also can make the following format:
# pragma comment (would/EXPORT: MyFunction=_MyFunction @ 4, "PRIVATE")
The role of PRIVATE and its role in the def file, more # pragram please see MSDN,
Summary: if you want to export functions in c + + files, and don't let the compiler function name, def file is used to derive the function,
At the same time can use the # pragma instruction can also be used in (C),
Conclusion:
In c + + compiler to generate DLL, adaptation, the name of the exported functions and different compiler USES adaptation rules are different, so the adaptation after name are different (typically involves the overloading in c + +, etc.),
If using different compiler generated DLL and visit DLL exe program respectively, the latter in to access the DLL's exported functions can be a problem, as above case MyFunction () function in c + + compiler adapted after's name is? MyFunction @ @ YGHH @ Z, we hope that the name of the compiled no change, there are several methods,
The first method is through a called DEF module definition files to resolve,
The LIBRARY TestDll
EXPORTS
MyFunction
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related