這段代碼應該編譯沒有錯誤,你應該鏈接-lcomdlg32
的對話框。如果我使用指針,程序將返回:0x22fcd8
或68
。並且應該(我認爲)在對話框中返回文件用戶類型的名稱。爲什麼lpstrFile在內存中返回地址而不是OPENFILENAMEW結構中的char數組?
#include <windows.h>
#include <iostream>
int main() {
wchar_t szFileName[MAX_PATH] = {0};
OPENFILENAMEW ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = szFileName;
GetSaveFileNameW(&ofn);
using namespace std;
cout << szFileName << endl;
cout << *szFileName << endl; // also a number not a string
}