User forums > Help
Strange error (win32 API)
seel:
Okay, i tried to compile the MDIapp example that comes with dev-cpp just to test windows.h in codeblocks. It compiles flawless in dev-cpp but not in codeblocks, i even copied the files and put them in a .cbp and i get this strange error:
(mdi_unit.c is the main file)
mdi_unit.c: In function `LoadFile':
mdi_unit.c:37: error: syntax error before "LPSTR"
mdi_unit.c: In function `SaveFile':
mdi_unit.c:69: error: syntax error before "LPSTR"
And here are the lines that don't work (they both look pretty much the same,except other variable name):
LPSTR pszFileText = LPSTR(GlobalAlloc(GPTR, dwFileSize + 1));
What's up with that LPSTR? If you need to see more of the code (and don't have dev-cpp installed) i could upload the files for you...
Pecan:
How in this world are we suppose to answer such a question without seeing the code or the project .cbp?
It says the err occured "before" LPSTR.
How about clicking on the code icon above (when posting a msg) and inserting some text before and after the error. Also turn on full compiler logging.
//-- Full Compile Logging --
Main Menu->Settings->Compiler and Debugger->"Other"->Compiler logging = "Full command line".
Paste the relevant results here.
seel:
Full code of mdi_unit.c: http://pastebin.ca/337163
The functions where the errors are in
--- Code: ---BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFFFF)
{
LPSTR pszFileText = LPSTR(GlobalAlloc(GPTR, dwFileSize + 1));
if(pszFileText != NULL)
{
DWORD dwRead;
if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
{
pszFileText[dwFileSize] = 0; // Null terminator
if(SetWindowText(hEdit, pszFileText))
bSuccess = TRUE; // It worked!
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
BOOL SaveFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
if(dwTextLength > 0)// No need to bother if there's no text.
{
LPSTR pszText=LPSTR(GlobalAlloc(GPTR, dwTextLength + 1));
if(pszText != NULL)
{
if(GetWindowText(hEdit, pszText, dwTextLength + 1))
{
DWORD dwWritten;
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
bSuccess = TRUE;
}
GlobalFree(pszText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
--- End code ---
These are all build messages i get and i turned on full command line:
Project : Win32 Application
Compiler : GNU GCC Compiler (called directly)
Directory : C:\Program\CodeBlocks\PROJEKT\dslua sdk\
--------------------------------------------------------------------------------
Switching to target: default
mingw32-gcc.exe -IC:\Program\CodeBlocks\include -c mdi_unit.c -o .objs\mdi_unit.o
mdi_unit.c: In function `LoadFile':
mdi_unit.c:37: error: syntax error before "LPSTR"
mdi_unit.c: In function `SaveFile':
mdi_unit.c:68: error: syntax error before "LPSTR"
Process terminated with status 1 (0 minutes, 2 seconds)
2 errors, 0 warnings
Biplab:
I think there's a cast problem. Change the following lines-
--- Code: ---LPSTR pszFileText = LPSTR(GlobalAlloc(GPTR, dwFileSize + 1));
--- End code ---
To
--- Code: ---LPSTR pszFileText = (LPSTR) GlobalAlloc(GPTR, dwFileSize + 1);
--- End code ---
and
--- Code: ---LPSTR pszText=LPSTR(GlobalAlloc(GPTR, dwTextLength + 1));
--- End code ---
To
--- Code: ---LPSTR pszText= (LPSTR) GlobalAlloc(GPTR, dwTextLength + 1);
--- End code ---
TDragon:
--- Quote from: Biplab on February 02, 2007, 06:03:06 pm ---I think there's a cast problem.
--- End quote ---
QFT. The original code demonstrates "C++-style casting" (functional notation) -- valid in C++ but not C.
Navigation
[0] Message Index
[#] Next page
Go to full version