Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

Another C# marshaling question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laurent - 28 Nov 2005 17:02 GMT
   Hi again,

   I created a thread some days ago, while I was trying to access a C++ DLL
using my C# program. First of all, I want to thanks all the guys who helped
me. But I still have a problem... My C++ DLL has a function which has the
following prototype:

   long FF_Function(void* inInstance, char* inDate, FF_Struct**
outStructure, long* outNumber);

   The structure has the following prototype:

   struct FF_Struct
       {
       long    m_Index;
       char    m_ID[FF_ID_LEN];
       char    m_Date[FF_DATETIME_LEN];
       };

   I know that the function should return me an array of FF_Struct, and
that the parameter outNumber has the number of elements stored in the
FF_Struct array. Now, I'm tring to translate it in C#, and here is what I
did (which does not work, of course):

   public class FF_AO_OrderList
       {
       public int index;
       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FF_ID_LEN)]
       public string numeroCommande;
       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FF_DATETIME_LEN)]
       public string dateCommande;
       }

   [DllImport("FF_myDLL.dll")]
   public static extern int FF_Function
       (
       IntPtr inInstance,
       [MarshalAs(UnmanagedType.LPTStr)]
       string date,
       out FF_Struct[] outStructure,
       out int outNumber
       );

   I can access the function, but it returns me an error message ("The
parameters specified for the interface are incorrect."). I don't know how to
deal with this structure and its double pointer. Even in unsafe mode (then I
use a FF_Struct** parameter), I have the same problem.

   Does anyone knows what I'm missing ? I'd greatly appreciate some help,
as I'm completely out of ideas... Thanks !!!!

   Laurent
Egbert Nierop (MVP for IIS) - 28 Nov 2005 21:35 GMT
>    Hi again,
>
[quoted text clipped - 27 lines]
>        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FF_ID_LEN)]
>        public string numeroCommande;

Try this
     [MarshalAs(UnmanagedType.ByvalArray,
ArraySubType=UnmanagedType.LPTstr, SizeConst = FF_DATETIME_LEN)]

>        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FF_DATETIME_LEN)]
>        public string dateCommande;
[quoted text clipped - 21 lines]
>
>    Laurent

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.