Generic Access to Special Folders

P

Paul Lyons

Hi,

I'm developing on WinXP and deploying on W2K so the path
to System32 directory is different on each system. I'm
trying to import DLLs from the Win32 API, but I have to
change the path and recompile before punching things up
to the server.

private const string SYSTEM32_PATH = @"C:\Winnt\System32
\"; // Or locally @"C:\Windows\System32\";
[DllImport(SYSTEM32_PATH + "Kernel32.dll")]
public static extern int GetLastError();

Is there a standard format for getting access to these
directories?? I thought it was something like %System%
but I think I've tried every combination of '/', '\'
and '%' to no avail. The help sytem has, as usual, not
lived upto it's name...!!

Thanks in advance
Paul
 
M

Marc Scheuner [MVP ADSI]

I'm developing on WinXP and deploying on W2K so the path
to System32 directory is different on each system.

Why not just use the Environment.SystemDirectory property?

Or if you need access to other "special" system directories, use the
Environment.GetFolderPath() method.

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
P

Paul Lyons

Thanks but I'd tried that...
I hadn't really expected it to work as the DllImport
requires a string constant at compile time and those
calls to Environment are evaluated at runtime..
And alas it didn't :-(

Hence I've been hunting for some sort of generic OS
recognised moniker for these particular directories.

It must exist, surely we don't have to recompile
components for clients who installed Windows on D:
instead of C:. Or for when MS, in their wisdom, decide to
change from "WINNT" to "Windows" and no doubt
to "Windows.Net" some time soon!
 
C

Chris Dunaway

private const string SYSTEM32_PATH = @"C:\Winnt\System32
\"; // Or locally @"C:\Windows\System32\";
[DllImport(SYSTEM32_PATH + "Kernel32.dll")]
public static extern int GetLastError();

When using dll's in the Windows system folders, I don't think it's
necessary to specify the full path to the .dll. I think you only need the
full path if the dll is not in a Windows system folder.

Can someone confirm or deny this?

Chris
 
P

Paul Lyons

That does seems to work! - Thanks

It's obvious really, 'cos the System32 directory is going
to be in the OS PATH list...
That's the trouble with amending someone elses code - I
forget how to think for myself!! They had put the full
path in, so I figured it was needed, and never looked
further than that :(
-----Original Message-----
[email protected]:


private const string SYSTEM32_PATH = @"C:\Winnt\System32
\"; // Or locally @"C:\Windows\System32\";
[DllImport(SYSTEM32_PATH + "Kernel32.dll")]
public static extern int GetLastError();

When using dll's in the Windows system folders, I don't think it's
necessary to specify the full path to the .dll. I think you only need the
full path if the dll is not in a Windows system folder.

Can someone confirm or deny this?

Chris
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top