Marshaling VB.Net Structure

0 pts.
Tags:
Development
I need to send a structure, containing strings, from VB.Net to unmanaged VC++ dll. In my VB.Net wrapper, there is the function declaration: Public Declare Ansi Function BDS_CapProc Lib "BDS_TK.dll" _ (ByRef in_cap As CapInput, ByRef outcap_eval As CapOutEval, _ ByRef outcap_annual As CapOutAnnual, ByRef outcap_intermed As CapOutIntermed) As Int16 The CapInput structure is defined as: <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _ Structure CapInput Dim CapCash() As Double Dim CapInfl() As Double Dim ProdIncFac() As Double Dim Pct_Replace As Double Dim CCA_Rate As Double Dim Salv_Fac As Double Dim Rem_Fac As Double Dim CR_Exp_Fac As Double Dim PIS_Exp_Fac As Double Dim Exp_Book_Fac As Double Dim Exp_Tax_Fac As Double Dim CFTiming As Int16 Dim OPST_apply As Int16 Dim QPST_apply As Int16 Dim TGET_exempt As Int16 Dim DSP_Treatment As Int16 Dim ComRetYr As Int16 Dim ComRetMth As Int16 Dim Life_Est As Int16 Dim Surv_Curve As Int16 Dim Scenario As Int16 Dim Mthly_Svc As Int16 Dim z_Fill As Int16 <MarshalAs(UnmanagedType.BStr)> _ Dim Cap_ID As String <MarshalAs(UnmanagedType.BStr)> _ Dim Cap_Description As String When I populate the CapInput structure, the data is good; when I send it to unmanaged code, the data is all corrupt. I have tried other variations of the <MarshalAs(UnmanagedType attribute (LPStr, LPWStr, LPTStr) all with the same reault. I have tried CharSet:=CharSet.Ansi and CharSet:=CharSet.Auto in the StructLayout attribute. Always the same result. The unmanaged code is in production, and works fine. It is currently called from Excel VBA. The structure definition is the same as above (except for the MarshalAs part, which is not need when calling from VBA). I have successfully passed managed structures containing only Doubles and Int16?s to the unmanaged code; no problem there. The other 3 structures in the above call contain no strings. So, I think the strings in the CapInput structure are hanging me up. Any ideas are appreciated.
ASKED: May 5, 2006  2:33 PM
UPDATED: May 9, 2006  12:06 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Is the string data fixed length?

Look at http://msdn2.microsoft.com/en-us/library/x14b6s77.aspx re the VBFixedStringAttribute.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Ppanke
    The string lengths are variable.
    0 pointsBadges:
    report
  • Mistoffeles
    Can you send fixed-length strings and allow the DLL to interpret them as variable-length by appending "n" to each string before sending the structure?
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following