Click here to Skip to main content
15,905,782 members
Home / Discussions / C#
   

C#

 
GeneralbeginInvoke() Pin
sreejith ss nair11-May-04 1:32
sreejith ss nair11-May-04 1:32 
GeneralRe: beginInvoke() Pin
Heath Stewart11-May-04 4:14
protectorHeath Stewart11-May-04 4:14 
GeneralRe: beginInvoke() Pin
Paul Watson11-May-04 4:14
sitebuilderPaul Watson11-May-04 4:14 
GeneralHTTP request,response Pin
dcronje11-May-04 1:05
dcronje11-May-04 1:05 
GeneralRe: HTTP request,response Pin
Heath Stewart11-May-04 4:05
protectorHeath Stewart11-May-04 4:05 
Generalhelp on wmi and registry Pin
chettu11-May-04 0:54
chettu11-May-04 0:54 
GeneralRe: help on wmi and registry Pin
Heath Stewart11-May-04 3:59
protectorHeath Stewart11-May-04 3:59 
GeneralRe: help on wmi and registry Pin
chettu11-May-04 20:18
chettu11-May-04 20:18 
GeneralRe: help on wmi and registry Pin
Heath Stewart12-May-04 2:52
protectorHeath Stewart12-May-04 2:52 
GeneralRe: help on wmi and registry Pin
chettu12-May-04 3:21
chettu12-May-04 3:21 
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 

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.