converting vb double to vc double
-
I know VB doubles are 4bits while VC doubles are 8. I'm passing a double from vb to a vc dll, how do I convert the data back and forth?
-
I know VB doubles are 4bits while VC doubles are 8. I'm passing a double from vb to a vc dll, how do I convert the data back and forth?
I don't know where you saw that VB doubles are 4 bit but they're not. They're exactly the same as VC doubles... From MSDN Visual Basic reference: Double data type A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. The number sign (#) type-declaration character represents the Double in Visual Basic. look up "type conversion functions"
Beware the chickens, for in their silence, they plot... Two fish are in a tank. One says to the other: "I'll man the guns, you drive!" Life is too short to be taken seriously. -- Oscar Wilde
-
I don't know where you saw that VB doubles are 4 bit but they're not. They're exactly the same as VC doubles... From MSDN Visual Basic reference: Double data type A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. The number sign (#) type-declaration character represents the Double in Visual Basic. look up "type conversion functions"
Beware the chickens, for in their silence, they plot... Two fish are in a tank. One says to the other: "I'll man the guns, you drive!" Life is too short to be taken seriously. -- Oscar Wilde
From what I understand the structure byte alignments for vb vs vc are 4 bytes and 8 bytes respectively. VB dynamically decides the byte alignment which is usually 4 but it can change it to optimize class structures. The reason I'm asking this is I'm passing a structure with a double array inside it from VB to a VC dll. When I change the value of the double array inside the dll, it doesn't change the vb value. I'm passing by reference. Here is my vb code:
Public Type assetvar cutoff_prin_bal(400) As Double End Type Public Type collateralvar subissue(100) As Integer asset As assetvar End Type Public Declare Function test Lib "PSAEngine.dll" Alias "_test@8" _ (ByVal j As Integer, ByRef collateral As collateralvar) As Double
The vc dll is:struct assetvar { double cutoff_prin_bal[400]; }; struct collateralvar { int subissue[100]; struct assetvar asset; }; __declspec( dllexport ) double test(int j, struct collateralvar *collateral);
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. Therefore they are not the same thing. -
From what I understand the structure byte alignments for vb vs vc are 4 bytes and 8 bytes respectively. VB dynamically decides the byte alignment which is usually 4 but it can change it to optimize class structures. The reason I'm asking this is I'm passing a structure with a double array inside it from VB to a VC dll. When I change the value of the double array inside the dll, it doesn't change the vb value. I'm passing by reference. Here is my vb code:
Public Type assetvar cutoff_prin_bal(400) As Double End Type Public Type collateralvar subissue(100) As Integer asset As assetvar End Type Public Declare Function test Lib "PSAEngine.dll" Alias "_test@8" _ (ByVal j As Integer, ByRef collateral As collateralvar) As Double
The vc dll is:struct assetvar { double cutoff_prin_bal[400]; }; struct collateralvar { int subissue[100]; struct assetvar asset; }; __declspec( dllexport ) double test(int j, struct collateralvar *collateral);
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. Therefore they are not the same thing.OK I see what you're trying to do but I haven't done VC in so long I've forgotten most of it :-O. I'm sure there's something I'm missing but I can't put my finger on it... Sorry.
Beware the chickens, for in their silence, they plot... Two fish are in a tank. One says to the other: "I'll man the guns, you drive!" Life is too short to be taken seriously. -- Oscar Wilde