Direct calls system dialog box in VC

xiaoxiao2021-03-06  105

(This is the first post to post, use an article written before, used as tests)

Yesterday, I asked me how to call the system's run dialog in the program, I started to feel is not difficult, there should be API functions, but I haven't found it in MSDN. Later, I thought that I could not open a public function, so I was searching for the Internet to see an example of the implementation under VB. He called the shell32.dll's unusless function RunfileDLG, not the system without the public. If you change it to the VC! I want to pass when the program starts.

GetProcaddress (Hlib, "Runfiledlg") can get the address of this function! But after tracking, get the result is always null, then use W32DSM to see that there is no such function in shell32.dll, I feel very strange. Later, I found that the function in the system is not open to find the address directly, but should call:

GetProcaddress (HLIB, (CHAR *) "61"); // 61 is RunfileDLG to export in shell32.dll, so that you can get the address of the function! The implementation of the code is simple, the code is as follows:

//

CString pszdllname = "shell32.dll";

Hinstance hlib = :: loadLibrary (pszdllname);

Char P [256];

Hicon ICO;

// I feel that the parameters should be lpcwstr, but online is LPCTSTR.

Typedef void (__stdcall * prunfiledlg) (HWND, Hicon, LPCTSTR, LPCTSTR, LPCTSTR, UINT);

Prunfiledlg Runfiledlg;

IF (HLIB == Null)

{

Return;

}

Runfiledlg = (prunfiledlg) getProcaddress (HLIB, (CHAR *) 61);

CString name = "Wolfbaby";

CString SSS = "Enterprise Path";

LPWSTR WNAME = New Wchar [100];

LPWSTR WSSS = New Wchar [100];

MEMSET (WNAME, 0, SIZEOF (WCHAR) * 100);

MEMSET (WSSS, 0, SIZEOF (WCHAR) * 100);

MultibyToWideChar (CP_ACP,

MB_PREComposed, // Character-Type Options

Name, // address of string to map

Name.getlength (), // Number of bytes in string

WNAME, / / ​​Address of Wide-Character Buffer

100

); // must be converted to wide character first, otherwise it will be called, the result is not right!

MultibyToWideChar (CP_ACP,

MB_PREComposed, // Character-Type Options

SSS, // address of string to map

Sss.getlength (), // Number of bytes in string

WSSS, // address of wide-character buffer100

);

IF (RunfiledLg! = null)

{

Runfiledlg (this-> getsafehwnd (),

NULL,

NULL,

(LPCTSTR) WNAME,

(Lpctstr) WSSS, 0x02);

}

:: Freelibrary (HLIB);

转载请注明原文地址:https://www.9cbs.com/read-96997.html

New Post(0)