Problem using WM5 and ShGetSpecialFolderPath

E

Erel

Hi,
I'm using this function to find some folders.
It works fine with WM2003 and Pocket PC 2002.
With WM5 it throws a native exception most of the times.
The weird thing is that if I show a messagebox before calling the
ShGetSpecialFolderPath then it will work.
Does anyone know of a safe solution for using this function with WM5?
Thanks,
Erel
 
P

Peter Foot [MVP]

Can you post a code snippet to illustrate this problem including your
P/Invoke declaration used?

Peter
 
E

Erel

This is the code:

[DllImport("coredll.dll")]
Private static extern bool SHGetSpecialFolderPath(
int hwndOwner,
string lpszPath,
int nFolder,
bool fCreate);

string sPath = new string(' ', 256);
bool ret;
this.Text = this.Text; //fixes the WM5 bug
ret = SHGetSpecialFolderPath(0, sPath, 2, false);

On my WM5 device and the WM5 emulator the line: this.Text = this.Text
solves the problem.
Thanks,
Erel
 
P

Peter Foot [MVP]

To return the string value you'll be safer passing a byte array or
StringBuilder to the API e.g.

[DllImport("coredll.dll", EntryPoint = "SHGetSpecialFolderPath",
SetLastError = false)]
internal static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner,
System.Text.StringBuilder lpszPath, int nFolder, int fCreate);

The OpenNETCF.EnvironmentEx class has a working example you can check out -
www.opennetcf.org/sdf/

Peter

--
Peter Foot
Windows Embedded MVP
www.peterfoot.net | www.inthehand.com

Erel said:
This is the code:

[DllImport("coredll.dll")]
Private static extern bool SHGetSpecialFolderPath(
int hwndOwner,
string lpszPath,
int nFolder,
bool fCreate);

string sPath = new string(' ', 256);
bool ret;
this.Text = this.Text; //fixes the WM5 bug
ret = SHGetSpecialFolderPath(0, sPath, 2, false);

On my WM5 device and the WM5 emulator the line: this.Text = this.Text
solves the problem.
Thanks,
Erel
Can you post a code snippet to illustrate this problem including your
P/Invoke declaration used?

Peter
 

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