473,387 Members | 1,859 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,387 software developers and data experts.

Unmanaged To Managed - Please Help

Hi

Please could someone help me with the following, i'm trying to port the unmanaged C++ below into either VB.Net or C# (i don't mind which).

Expand|Select|Wrap|Line Numbers
  1.  
  2. typedef struct {
  3.   U32 Size;
  4.   U32 Start;
  5.   U32 Reserved1;
  6.   U32 Reserved2;
  7. } EVENT_INFO;
  8.  
  9. typedef enum {
  10.   EVENT_ERASE,
  11.   EVENT_PROGRAM,
  12.   EVENT_VERIFY
  13. } EVENT_TYPE;
  14.  
  15. typedef void EVENT_FUNC(EVENT_TYPE event, const EVENT_INFO * info);
  16.  
  17. STDCALL void SetProgressEvent (EVENT_FUNC * eventFunc);
  18.  
  19.  
For clarity, i will post the code i have written so far in a reply. Basically, all the above code does is provide feeback on erase, write and verify cycles when programming a microprocessor.

Thanks in advance

Kev
Sep 15 '09 #1
2 1254
The code i have so far is...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Friend Structure ProgressInformation
  3.     Public Size As UInt32
  4.     Public Start As UInt32
  5.     Public Reserved1 As UInt32
  6.     Public Reserved2 As UInt32
  7. End Structure
  8.  
  9. Friend Enum ProgressEvent
  10.     ChipErase
  11.     Program
  12.     Verify
  13. End Enum
  14.  
  15. <UnmanagedFunctionPointer(CallingConvention.StdCall)> _
  16. Public Delegate Sub ProgressDelegate(ByVal progressEvent As ProgressEvent, ByVal state As ProgressInformation)
  17.  
  18. <DllImport(LIBRARY, EntryPoint:="SetProgressEvent ", CallingConvention:=CallingConvention.StdCall)> _
  19. Friend Shared Sub SetProgressHandler(ByVal notifyHandler As ProgressDelegate)
  20.     ' Empty method body
  21. End Sub
  22.  
  23.  

I use the imported method as follows...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub UpdateProgress(ByVal progressEvent As ProgressEvent, ByVal state As ProgressInformation)
  3.     Console.WriteLine(progressEvent.ToString())
  4.     Console.WriteLine("Size:{0}, Start:{1}, Reserved1:{2}, Reserved2:{3}", state.Size, state.Start, state.Reserved1, state.Reserved2)
  5. End Sub
  6.  
  7. ...
  8. Public Sub New()
  9. .... other initialisation code here
  10.  
  11.     SetProgressHandler(AddressOf UpdateProgress)
  12.  
  13. .... other dispose code here
  14. End Sub
  15.  
Now, the first time the UpdateProgress method runs i get valid data in the structure. As soon as the method returns, i get an AccessViolationException saying that the memory is corrupt. I'm thinking its something related to the way i've declared the import but i'm struggling to understand what.

Once again, thanks for any help in advance

Kev
Sep 15 '09 #2
And the answer is.... CDECL not STDCALL
Sep 16 '09 #3

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

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
8
by: Don | last post by:
I have a third party C++ DLL that I am trying to use from C#. The specific function I am trying to use is declared in C++ as follows: ladybugConvertToMultipleBGRU32( LadybugContext ...
12
by: MuZZy | last post by:
HI, Say i have a class(on C++) which has an unmanaged STL member of STRMAP which is a define for map<string, string>. class CL { public CL(){mp = new STRMAP()}; public void Dispose(delete...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
0
by: Johannes Unfried | last post by:
Problem Best practice needed to marshal STL data from managed code to unmanaged code & vice vers Details managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a...
2
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking afterwards with ILDASM at what is visible in those assemblies from a...
3
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
5
by: ttc | last post by:
Hi All, I have a managed class that inherits from an unmanged class. The question is, if the object of the manged class get garbage collected, will the memory be free automatically for me or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.