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

PInvoke

Here is my issue, I am very new to C# and want to invoke a custom dll that I can't register using regsvr32. I figured out I need to use PInvoke somehow but need help since all the methods return void, the data is in the Msg pointer. Some of the functions will need to send data using Msg and then will receive back in a modified pointer.

Here is one example the message is a structure that is passed to GetTMVersionInfo ( TM_Message* Msg ) and by sending a blank message it will modify the TM_Message pointer with the real data. The dll is for a keyboard I need to write drivers to, a Bosch Intuikey.


typedef struct
{
BYTE Msg[MAX_MSG_LEN];
int MsgLen;
} TM_Message;

TM_Message will be used as an output parameter for all API’s. All API’s will return the formed packet in
TM_Message structure.
• Msg will be the framed packet.
• MsgLen will be the length of packet.
• MAX_MSG_LEN is a macro, having value 80.


void GetTMVersionInfo ( TM_Message* Msg )
This API will be used to form packet for information message “Get_Version”. Formed packet will return in output parameter TM_Message.
Input Parameters: None
Return Type: Void

remember I am new to C# and not good at C, been a while so type slowly so I can understand :-)

Thanks
John
Dec 10 '09 #1

✓ answered by grndvl1

Actually i found the answer here it is

[StructLayout(LayoutKind.Sequential)]
public struct TM_Message {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ConstantsUsed.MAX_MSG_LEN)]
public byte[] data;
public int MsgLen;
};

public static class ConstantsUsed {
public const int MAX_MSG_LEN = 80;
}

and then make the dll calls

[DllImport("terminalModeDll.dll")]
private static extern void GetTMVersionInfo(ref TM_Message msg);

and then make a generic method wrapper to do any processing:

public TM_Message m_GetTMVersionInfo(TM_Message message) {
GetTMVersionInfo(ref message);
return message;
}

2 2800
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. void GetTMVersionInfo ( TM_Message* Msg )
  2.  
Are you changing the value of *Msg in this function.?

Regards
Dheeraj Joshi
Dec 11 '09 #2
Actually i found the answer here it is

[StructLayout(LayoutKind.Sequential)]
public struct TM_Message {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ConstantsUsed.MAX_MSG_LEN)]
public byte[] data;
public int MsgLen;
};

public static class ConstantsUsed {
public const int MAX_MSG_LEN = 80;
}

and then make the dll calls

[DllImport("terminalModeDll.dll")]
private static extern void GetTMVersionInfo(ref TM_Message msg);

and then make a generic method wrapper to do any processing:

public TM_Message m_GetTMVersionInfo(TM_Message message) {
GetTMVersionInfo(ref message);
return message;
}
Dec 18 '09 #3

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

Similar topics

4
by: Ted | last post by:
Is it possible to use mailslots in .NET using PInvoke? I have a VC++ 6.0 based app that creates and listens to a mailslot. I have a second VC++ 6.0 based app that opens the mailslot and writes...
5
by: Carlos Guzmán Álvarez | last post by:
Hello: I'm trying to execute a function of a unmanaged dll using PInvoke, i have definied the function as: public static extern int isc_dsql_prepare( int status_vector, ref int...
3
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is...
5
by: vertigo | last post by:
Hello I use some win 32 API function for example: HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD...
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)...
1
by: cppdev | last post by:
Hello, After reading a few articles, http://blogs.gotdotnet.com/cbrumme/PermaLink.aspx/e55664b4-6471-48b9-b360-f0fa27ab6cc0...
5
by: _iycrd | last post by:
After numerous problems, I'm having second thoughts about using C++/CLI to wrap a native DLL. On the other hand, PInvoke seems like it will take a huge amount of work, if it will work at all. ...
8
by: Rajesh Soni | last post by:
Hi! I'm getting a PInvoke error while trying to execute the following code... declaration: Structure POINTAPI Dim x As IntPtr
0
by: Benosham | last post by:
I have been playing around with trying to PInvoke GDI+ from C#, I made recently made the transition from C/C++ to C# and I really like the language, however being the old fashioned programmer I am I...
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...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.