Click here to Skip to main content
15,896,502 members
Home / Discussions / C#
   

C#

 
Generalblock the keyboard Pin
cristina_tudor11-May-04 0:36
cristina_tudor11-May-04 0:36 
GeneralRe: block the keyboard Pin
Corinna John11-May-04 0:50
Corinna John11-May-04 0:50 
GeneralReturning string from unmanaged dll Pin
Mikke_x10-May-04 23:50
Mikke_x10-May-04 23:50 
GeneralRe: Returning string from unmanaged dll Pin
Heath Stewart11-May-04 3:31
protectorHeath Stewart11-May-04 3:31 
GeneralRe: Returning string from unmanaged dll Pin
Mikke_x11-May-04 4:06
Mikke_x11-May-04 4:06 
GeneralRe: Returning string from unmanaged dll Pin
Heath Stewart11-May-04 4:59
protectorHeath Stewart11-May-04 4:59 
GeneralRe: Returning string from unmanaged dll Pin
Mikke_x11-May-04 5:02
Mikke_x11-May-04 5:02 
GeneralRe: Returning string from unmanaged dll Pin
Heath Stewart11-May-04 5:20
protectorHeath Stewart11-May-04 5:20 
That's correct, so the problem is in your unmanaged code. How is m_Devices declared? What codepage is Windows set up for? Are you using a different codepage for your Console? Also, since your using just printf and not tprintf, this tells me you're not using ASCII on Windows and Unicode on Windows NT (like Auto dictates), so use CharSet.Ansi instead (if this is the case). Like I said before, you should read the documentation, not just expect the exact answer (especially when you don't provide enough details to say for sure).

One thing I would warn you about as well is that it's actually a bad idea to return strings from functions. I don't remember all the details (it's been a while since I was hot n' heavy into C/C++), but you should instead declare your function like so:
__declspec(dllexport) void GetString(INT i, LPSTR lpszText, DWORD cbText);
Also notice my use of INT (declared as int, and it's typically better to use pre-proc defs). The lpszText param is both [in,out], and the cbText ([in]) is the max string length. Without this protection, you open your code up - and potentially your entire system - to buffer overruns (the leading cause of security threats). This signature is common for functions and structs throughout the Windows APIs.

Your managed declaration would then look like this (taking into account that is seems you're using ASCII only strings since you're using
printf</code):<pre>[DllImport("pciDriver.dll", CharSet=CharSet.Ansi)]<br />
private static extern void GetString(<br />
  int i,<br />
  [In, Out] string lpszText,<br />
  [MarshalAs(UnmanagedType.U4)] int cbSize);</pre>Technically, however, the first param - <codE>i
- should be an IntPtr. An int in C# refers to Int32, which is always 32 bits. An int in C/C++ is the width of the processor, so 32 bits on a 32-bit processor and 64 bits on a 64-bit processor (depends on the compiler, really). An IntPtr is like that. If you wanted to make your code more portable to other architectures, then change the param type to IntPtr and when you pass it, pass it as new IntPtr(0) (or whatever index you need).

 

Microsoft MVP, Visual C#
My Articles
QuestionFont to LOGFONT ? Pin
azusakt10-May-04 23:06
azusakt10-May-04 23:06 
AnswerRe: Font to LOGFONT ? Pin
Kannan Kalyanaraman10-May-04 23:22
Kannan Kalyanaraman10-May-04 23:22 
GeneralRe: Font to LOGFONT ? Pin
Heath Stewart11-May-04 3:40
protectorHeath Stewart11-May-04 3:40 
GeneralRe: Font to LOGFONT ? Pin
azusakt11-May-04 16:55
azusakt11-May-04 16:55 
GeneralRe: Font to LOGFONT ? Pin
Heath Stewart12-May-04 2:45
protectorHeath Stewart12-May-04 2:45 
GeneralRe: Font to LOGFONT ? Pin
azusakt11-May-04 22:41
azusakt11-May-04 22:41 
GeneralRe: Font to LOGFONT ? Pin
azusakt12-May-04 15:20
azusakt12-May-04 15:20 
GeneralSockets Pin
bouli10-May-04 22:58
bouli10-May-04 22:58 
GeneralRe: Sockets Pin
Heath Stewart11-May-04 3:44
protectorHeath Stewart11-May-04 3:44 
GeneralQuartz.dll Pin
MeterMan10-May-04 22:51
MeterMan10-May-04 22:51 
GeneralRe: Quartz.dll Pin
Heath Stewart11-May-04 3:46
protectorHeath Stewart11-May-04 3:46 
GeneralString question Pin
pankajdaga10-May-04 22:26
pankajdaga10-May-04 22:26 
GeneralRe: String question Pin
Kannan Kalyanaraman10-May-04 23:07
Kannan Kalyanaraman10-May-04 23:07 
Generalthanks! Pin
pankajdaga10-May-04 23:22
pankajdaga10-May-04 23:22 
GeneralGet The Time When The Program Execute Pin
DucLinh10-May-04 21:27
DucLinh10-May-04 21:27 
GeneralRe: Get The Time When The Program Execute Pin
Mazdak10-May-04 21:41
Mazdak10-May-04 21:41 
GeneralRe: Get The Time When The Program Execute Pin
DucLinh10-May-04 22:09
DucLinh10-May-04 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.