gpt4 book ai didi

c++ - GetOpenFileName 触发断点

转载 作者:行者123 更新时间:2023-11-28 08:11:34 28 4
gpt4 key购买 nike

我正在尝试这样调用 GetOpenFileName:

int main(int argc, char* argv[])
{

OPENFILENAME ofn; // common dialog box structure
wchar_t szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
wchar_t title[500]; // to hold title
GetConsoleTitle( title, 500 );
HWND hwndConsole = FindWindow( NULL, title );
ofn.hwndOwner = hwndConsole;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = L"All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

// Display the Open dialog box.

if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile,
GENERIC_READ,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);

prog 在“if (GetOpenFileName(&ofn)==TRUE)”处停止(消息:example.exe 已触发断点(不是我放置的断点))当我中断时,我收到一条消息,指出没有可用的源。如果我没有中断,只是按继续,对话框会弹出并按预期工作。我究竟做错了什么?我只是注意到它在 Release模式下没有问题......

最佳答案

一个可能的问题:ofn.nMaxFile 应该是字符数,而不是缓冲区的字节大小。试试这个:

ofn.nMaxFile = sizeof(szFile) / sizeof(wchar_t);

关于c++ - GetOpenFileName 触发断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8949441/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com