error bad dll calling convention
-
I'm getting the error bad dll calling convention when I call my dll written in vc++ from my vb app. The problem is because of the type / structure I'm passing my dll. In vb, I've defined my call to the dll and created a type in vb that looks like this:
Declare Function test Lib "C:\TEMP\EngineTest\PSAEngine.dll" Alias "_test@10004" _ (ByVal j As Integer, ByRef collateral As collateralvar) Type assetvar cutoff_prin_bal(400) As Double orig_gross_rate(400) As Double orig_amort_term(400) As Double End Type Type collateralvar subissue(100) As Integer asset As assetvar End Type
In my VC++ dll, I've defined my function and structure as:extern "C" { __declspec( dllexport ) void test(int j, collateralvar collateral); } struct assetvar { double cutoff_prin_bal[400]; double orig_gross_rate[400]; double orig_amort_term[400]; }; struct collateralvar { int subissue[100]; struct assetvar asset; };
Here is my call to the dll function:Static collateral As collateralvar . . . test 0, collateral
When I call the function test in my vb program it returns the error Bad DLL calling convention. Any ideas? -
I'm getting the error bad dll calling convention when I call my dll written in vc++ from my vb app. The problem is because of the type / structure I'm passing my dll. In vb, I've defined my call to the dll and created a type in vb that looks like this:
Declare Function test Lib "C:\TEMP\EngineTest\PSAEngine.dll" Alias "_test@10004" _ (ByVal j As Integer, ByRef collateral As collateralvar) Type assetvar cutoff_prin_bal(400) As Double orig_gross_rate(400) As Double orig_amort_term(400) As Double End Type Type collateralvar subissue(100) As Integer asset As assetvar End Type
In my VC++ dll, I've defined my function and structure as:extern "C" { __declspec( dllexport ) void test(int j, collateralvar collateral); } struct assetvar { double cutoff_prin_bal[400]; double orig_gross_rate[400]; double orig_amort_term[400]; }; struct collateralvar { int subissue[100]; struct assetvar asset; };
Here is my call to the dll function:Static collateral As collateralvar . . . test 0, collateral
When I call the function test in my vb program it returns the error Bad DLL calling convention. Any ideas?use __stdcall in the function you declare in c++ to solve the calling convention problem
-
use __stdcall in the function you declare in c++ to solve the calling convention problem
void __stdcall test(int j, collateralvar collateral);
This doesn't work because your back to not being able to find DLL entry point. It must be declared as__declspec( dllexport ) void test(int j, collateralvar collateral);
-
void __stdcall test(int j, collateralvar collateral);
This doesn't work because your back to not being able to find DLL entry point. It must be declared as__declspec( dllexport ) void test(int j, collateralvar collateral);
OK. I've gotten into the vc dll. I added a struct command and made it a pointer. vc dll
__declspec( dllexport ) double test(int j, struct collateralvar *collateral)
vb declarePublic Declare Function test Lib "PSAEngine.dll" Alias "_test@8" _ (ByVal j As Integer, ByRef collateral As collateralvar) As Double
Now my problem is changing the values inside the dll's collateralvar struct and having vb see them. I'm passing the structure by reference so it should work but its not. Here is what I am doing inside the dll function:__declspec( dllexport ) double test(int j, struct collateralvar *collateral) { collateral->asset.cutoff_prin_bal[j]=14; return(1); }
from VB I'm calling the dll this way:dim x as double collateral.asset.cutoff_prin_bal(0) = 423149.74 x = test(0, collateral)
I still get 423149.74 instead of 14.0