www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - GetOpenFileName problem

reply Trass3r <mrmocool web.de> writes:
I want to use the GetOpenFileName function in D (with DFL btw), the problem is,
the linker doesn't find it cause it searches for _GetOpenFileName
but comdlg32.dll seems to export it as GetOpenFileName.

pragma(lib,"comdlg32.lib");
export extern(C) BOOL GetOpenFileName(OPENFILENAME* lpofn);
Feb 27 2008
next sibling parent Trass3r <mrmocool web.de> writes:
Never mind, was a really dumb mistake, I forgot that I have to use
GetOpenFileNameA resp. GetOpenFileNameW.
Feb 27 2008
prev sibling parent reply Trass3r <mrmocool web.de> writes:
Got another problem now. GetOpenFileName fails with error code 2
(Initialization error)
Can't figure out why it fails:

		string filter="DK2 string files(*.str)\0*.str\0\0";
		string filename;
		filename.length=400;
		OPENFILENAME ofn;
		memset(&ofn,0,ofn.sizeof);
		ofn.lStructSize=OPENFILENAME.sizeof;
		ofn.hwndOwner=null;
		ofn.lpstrFilter=filter.ptr;
		ofn.lpstrCustomFilter=null;
		ofn.lpstrFile=filename.ptr;
		ofn.nMaxFile=filename.length;
		
		if (!GetOpenFileNameA(&ofn))
		{
			debug msgBox("CommDlgError: "~std.string.toString(CommDlgExtendedError()));
			return;
		}

Maybe because of hwndOwner? But I don't know how to get the hwnd in DFL.
Feb 28 2008
parent "Chris Miller" <chris dprogramming.com> writes:
On Thu, 28 Feb 2008 16:06:42 -0500, Trass3r <mrmocool web.de> wrote:

 Got another problem now. GetOpenFileName fails with error code 2  =
 (Initialization error)
 Can't figure out why it fails:

 		string filter=3D"DK2 string files(*.str)\0*.str\0\0";
 		string filename;
 		filename.length=3D400;
 		OPENFILENAME ofn;
 		memset(&ofn,0,ofn.sizeof);
 		ofn.lStructSize=3DOPENFILENAME.sizeof;
 		ofn.hwndOwner=3Dnull;
 		ofn.lpstrFilter=3Dfilter.ptr;
 		ofn.lpstrCustomFilter=3Dnull;
 		ofn.lpstrFile=3Dfilename.ptr;
 		ofn.nMaxFile=3Dfilename.length;
 		=
 		if (!GetOpenFileNameA(&ofn))
 		{
 			debug msgBox("CommDlgError:  =
 "~std.string.toString(CommDlgExtendedError()));
 			return;
 		}

 Maybe because of hwndOwner? But I don't know how to get the hwnd in DF=
L. Controls and Forms have a handle property to get the HWND, but why not = just use DFL's OpenFileDialog: = http://wiki.dprogramming.com/DflDoc/Filedialog - it wraps all this messy= = winapi into a nice class.
Mar 13 2008