|
-
September 27th, 2008, 07:54 AM
#1
Winapi C++ retrieve variable
Im writing another function (save function) that involves retrieving the filename - variable "szFileName" from this function...but I dont exactly know how to do the retrieving part....I figured it would involve pointers but i am not too good with pointers
Code:
BOOL Load(HWND hwnd, BOOL bSave)
{
OPENFILENAME ofn;
char szFileName[MAX_PATH];
ZeroMemory(&ofn, sizeof(ofn));
szFileName[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0HTML Files (*.html)\0*.html\0HTM Files (*.htm)\0*.htm\0PHP Files (*.php)\0*.php\0UnkEdit Files (*.uke)\0*.uke\0All Files (*.*)\0*.*\0\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "txt";
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn))
{
if(!LoadFile(GetDlgItem(hwnd, EDIT_TEXT), szFileName))
{
MessageBox(hwnd, "Load of file failed.", "Error",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
}
return TRUE;
}
-
September 27th, 2008, 11:51 AM
#2
Re: Winapi C++ retrieve variable
If you just want to return a string pointer, use this template:
Code:
LPCTSTR MyFunc(int x, int y)
{
static TCHAR szReturn[MAX_PATH];
// Fill in szReturn here
return szReturn;
}
If you really need to return a BOOL:
Code:
BOOL MyFunc(int x, int y, LPTSTR lpString, UINT cbString)
{
// Do your thing here
_tcsncpy_s(lpString, cbString, szFilename, sizeof(szFilename)/sizeof(szFilename[0]));
return FALSE;
}
-Erik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|