473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem using PInvoke to interact with a C++ dll

1
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Declare Sub GetReplyData3 Lib "WfRelay.dll" (ByVal S As Variant, ByVal P As Long, N As Currency)
  3.  

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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. [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);
  3.  
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.

Thanks.
Mar 19 '08 #1
0 1052

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: nicolasr | last post by:
Hi, I need to PInvoke the ExtCreateRegion API. How do I declare the structures used by it and the function itself in C#? The original declarations are: typedef struct _RGNDATAHEADER {...
2
by: Craig | last post by:
I've seen many examples of how to call SHGetFileInfo in shell32.dll to get a files associated icon, but I can't find anywhere how to get the file information (size, last date modified, etc, etc)...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
14
by: Christian Kaiser | last post by:
We have a component that has no window. Well, no window in managed code - it uses a DLL which itself uses a window, and this is our problem! When the garbage collector runs and removes our...
8
by: Rob R. Ainscough | last post by:
I have a VS 2005 Windows Service with a Installer project as part of my solution. The Service installs fine but I can't seem to make either of these work: 1. Have the service start after...
6
by: gregarican | last post by:
I am trying to port a legacy CTI application written in another programming language to C# 2005. From my initial research into it I see I can utilize the DllImport method to tap into the DLL file...
1
by: Kevin Erickson | last post by:
Hello, I am attempting to use pexpect in python to copy files from a server using scp; the copy works however exceptions are thrown and it exits unsuccessfully. Below is the a sample code and...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
2
by: =?Utf-8?B?aGVsZmk=?= | last post by:
Hi all, I have replied with my own questions to an older post entry but after a while I thought it's better to start a new thread based on the previous one. Perhaps with the new thread I will...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.