Problem using PInvoke to interact with a C++ dll

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem using PInvoke to interact with a C++ dll

  1. #1
    Join Date
    Mar 2008

    Smile Problem using PInvoke to interact with a C++ dll

    Hi There,

    I am quite new to PInvoke and calling COM functions from C#.

    I have managed so far to call some unmanaged functions ib my C++ dll from my C# code but at the moment I am having trouble with one particular function.

    I have a sample of the function being correctly defined in some VB6 code below.

    Declare Sub GetReplyData3 Lib "WfRelay.dll" (ByVal S As Variant, ByVal P As Long, N As Currency)

    I am able to call the COM function from the VB 6 code using this declaration.
    The VB code calls the function and passes it a fixed length string as the variant, a long and a currency.

    I have to call this function from C# though and i think it may be the first parameter that I am having my troubles with.

    I call it as seen below:

    [DllImport("C:\\Program Files\\Microsoft Outlook\\OFFICE11\\WfRelay.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)] 
    public static extern void GetReplyData3(object severReply, int P, [MarshalAs(UnmanagedType.Currency)] decimal N);
    I believe that I am Marshalling third parameter the Currency correctly.

    I think it is in the first parameter I think I have my issue. I am passing an object to the variant at the moment. I have read this is the correct way of talking to a variant from .Net and have done so successfully for other functions.
    This variant though is manipulated by the function and this is why I think I have the issue.
    I have also tried sending a StringBuilder to the function as the Variant is sent as a fixed length string in the VB6 code.
    This also would not work though.

    The error message that I get is "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.".

    I have also tried sending various string types and fixed length character arrays but all to no avail.

    I would really appreciate it if you could help me out with this.

    Last edited by AlDev; 03-19-2008 at 01:52 PM.

  2. #2
    Join Date
    Oct 2005
    try the .Net section it's C# issue .. not a micro$oft operating system API's ..
    Programmer&Cracker CS

  3. #3
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Moved to .NET

Similar Threads

  1. I have a problem with dll registerserver
    By hamaimiy in forum VB Classic
    Replies: 6
    Last Post: 07-17-2007, 04:12 AM
  2. Replies: 5
    Last Post: 07-20-2001, 02:25 PM
  3. Re: Dll function call problem - Same problem
    By Fabian in forum VB Classic
    Replies: 7
    Last Post: 06-28-2000, 12:54 PM
  4. Dll function call problem
    By Pete Mitchell in forum VB Classic
    Replies: 6
    Last Post: 06-28-2000, 07:13 AM
  5. Re: Updating ActiveX DLL
    By Sam Wood in forum Enterprise
    Replies: 0
    Last Post: 05-17-2000, 01:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center