Re: how to declare GetOpenFileNameEx in C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Try this:


LPOPENFILENAMEEX t = new LPOPENFILENAMEEX();
t.lStructSize = Marshal.SizeOf(typeof(LPOPENFILENAMEEX));
t.hInstance = GetModuleHandle(null);
t.hwndOwner = this.Handle;

t.Flags = 2;
t.lpstrFilter = "All Files (*.*)\0*.*\0";
t.lpstrFile = Marshal.AllocHGlobal(250);
t.nMaxFile = 250;
t.lpstrTitle = "Select";

if (GetOpenFileNameEx(ref t))
MessageBox.Show(Marshal.PtrToStringUni(t.lpstrFile));

Marshal.FreeHGlobal(t.lpstrFile);

....


public struct LPOPENFILENAMEEX
{
public int lStructSize;
public IntPtr hwndOwner;
public IntPtr hInstance;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpstrFilter;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpstrCustomFilter;
public int nMaxCustFilter;
public int nFilterIndex;
public IntPtr lpstrFile;
public int nMaxFile;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpstrFileTitle;
public int nMaxFileTitle;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpstrInitialDir;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpstrTitle;
public int Flags;
public short nFileOffset;
public short nFileExtension;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpstrDefExt;
public IntPtr lCustData;
public IntPtr lpfnHook;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpTemplateName;

// Extended fields
public int dwSortOrder;
public int ExFlags;
}

[DllImport("coredll.dll")]
private static extern IntPtr GetModuleHandle(string m);
[DllImport("Aygshell.dll")]
private static extern bool GetOpenFileNameEx(ref LPOPENFILENAMEEX lpofnex);


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com


Magic Gooddy wrote:
I know about it. But I want to see how to work this function in C# for WM50

"Peter Foot [MVP]" <feedback@xxxxxxxxxxxxxxxxxxxx> сообщил/сообщила в новостях следующее: news:Ox2nWnIQGHA.2256@xxxxxxxxxxxxxxxxxxxxxxx
GetOpenFileNameEx is specific to WindowsMobile 5.0. You can use the Microsoft.WindowsMobile.Forms.SelectPictureDialog which wraps this API

Peter

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

"Magic Gooddy" <gooddy@xxxxxxxxxx> wrote in message news:%23kIfdNHQGHA.2696@xxxxxxxxxxxxxxxxxxxxxxx
Hi!
How to declare GetOpenFileNameEx API function in C#?


.



Relevant Pages

  • Re: RasEnumEntries returns only 1 dial up entry (PocketPC)
    ... public int reserved1 = 0; ... public string szPhoneNumber; ... public extern static uint RasHangUp( ... // buffer to hold error string ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Eigenschaftsdialog modal anzeigen
    ... public int cbSize; ... public string lpVerb; ... public IntPtr hInstApp; ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: ShellExecute problems
    ... public IntPtr hMonitor; ... public int cbSize; ... public string lpVerb; ... public static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO si); ...
    (microsoft.public.dotnet.framework)
  • RE: WNetAddConnection2
    ... I managed to recreate my error from the command prompt with the following ... So I got to thinking about the username and tried ... ... public int dwScope; ... public string lpRemoteName; ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Which generic?
    ... public string description; ... static void Main ... foreach(Column col in myCols) ... public int IndexOf{ ...
    (microsoft.public.dotnet.languages.csharp)