Hello William DePalo [MVP VC++],
Wouldn't you recommend IJW, and handling the marshling (via Marshal::XXX
methods) manually versus DllImport style ? I would think IJW performs better,
no ?
Thanks, RBischoff
W> "Harry Whitehouse" <ha***@envmgr.c om> wrote in message
W> news:ej******** ******@TK2MSFTN GP12.phx.gbl...
W>
Hi Will!
W> Hello.
W> When I try this:
Form1(void)
{
InitializeCompo nent();
TCHAR WinPath[_MAX_PATH+1]="";
GetWindowsDirec tory(WinPath,_M AX_PATH);
}
I get these compiler errors:
c:\junkfuck\For m1.h(51): error C3861: 'GetWindowsDire ctory':
identifier
not found, even with argument-dependent lookup
c:\junkfuck\For m1.h(270): error C2065: 'WindowsDir' : undeclared
identifier
I've used this API call in straight windows before many times, but I
can't get it recognized in the .NET environment!
W> Right. That's because in the .Net environment, an application is
W> expected to use the framwork. You can "drop down" to the level of the
W> API but it is some work to do so. It wouldn't surprise me if there is
W> a class in .Net with a method to get what you want. I don't have time
W> now to do the research.
W>
W> As for using the API, you have two choices. One is Platform Invoke
W> aka P/Invoke. This is an example
W>
W> #include "stdafx.h"
W> #using <mscorlib.dll >
W> using namespace System;
W> using namespace System::Runtime ::InteropServic es;
W> [ DllImport("Kern el32.dll", EntryPoint="Get WindowsDirector yW",
W> CallingConventi on=CallingConve ntion::StdCall) ]
W> extern "C" int GetWindowsDirec tory(wchar_t *, unsigned int);
W> int _tmain()
W> {
W> wchar_t wszDir[260];
W> GetWindowsDirec tory(wszDir, sizeof(wszDir)) ;
W>
W> return 0;
W> }
W> Note that I hardcoded the size of the string. That's bad and only
W> done here as an expedient.
W>
W> Another option is to use "it just works". IJW lets you have a managed
W> caller call into an unmanaged function. To do that, I'd suggest
W> putting the native API call in a module which does not use the
W> framework and which is not compiled with the /CLR option.
W>
W> Regards,
W> Will