Full code of mdi_unit.c: http://pastebin.ca/337163
The functions where the errors are in
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;
}
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
I think there's a cast problem. Change the following lines-
LPSTR pszFileText = LPSTR(GlobalAlloc(GPTR, dwFileSize + 1));
To
LPSTR pszFileText = (LPSTR) GlobalAlloc(GPTR, dwFileSize + 1);
and
LPSTR pszText=LPSTR(GlobalAlloc(GPTR, dwTextLength + 1));
To
LPSTR pszText= (LPSTR) GlobalAlloc(GPTR, dwTextLength + 1);
Oh, it was that simple eh? doh :lol:
Well, now i get another error...
Project : Win32 Application
Compiler : GNU GCC Compiler (called directly)
Directory : C:\Program\CodeBlocks\PROJEKT\dslua sdk\
--------------------------------------------------------------------------------
Switching to target: default
mingw32-g++.exe -IC:\Program\CodeBlocks\include -c mdi_unit.cpp -o .objs\mdi_unit.o
mingw32-g++.exe -LC:\Program\CodeBlocks\lib -o "C:\Program\CodeBlocks\PROJEKT\dslua sdk\DSLuaSDK.exe" .objs\mdi_unit.o .objs\mdi_res.res -lgdi32 -luser32 -lkernel32 -mwindows
.objs\mdi_unit.o:mdi_unit.cpp:(.text+0x2d0): undefined reference to `InitCommonControls@0'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 12 seconds)
0 errors, 0 warnings
And here is where the function is located in the code
...
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
MSG Msg;
WNDCLASSEX WndClassEx;
InitCommonControls();
g_hInst = hInstance;
....