PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Problem opening a file with fopen...

When I try to open a file with fopen, I get a NULL...
and I know the file exist...
is there something diffrent about opening files on PocketPC's?
I do it something like this:
Code:

const char FileName[]="test.bmp";
FILE *pFile(FileName,"r");

and then pFile is NULL...
why is that?
You mean
Code:

FILE *pFile;
pFile=fopen(FileName,"r");


Yes that should work, assuming you are in the correct directory.
Tala wrote:Yes that should work, assuming you are in the correct directory.


There is no "current" directory on Pocket PCs. You have to use the full path.
Thierry":3dm365lv]
is there a GetCurrentDirectory function for PPC?
because I tried to use it and it says that he cant find this function...
ilanprod wrote:is there a GetCurrentDirectory function for PPC?
because I tried to use it and it says that he cant find this function...


There is none. You can use GetModuleFileName() with the handle parameter set to 0. This will return you the full path of your .exe. You can then strip the last part (the exe's filename) and replace it with your image filename.

If you need an example, PocketFrog does this: look for a function named GetFullPathName().
It's been posted before I think, but here's my version of that code, feel free to use it...

Code:

DWORD GetModuleDirectory(HMODULE hModule, LPTSTR szPath, DWORD dwLength) {

DWORD dwLen;
LPTSTR p;
if (0 == (dwLen = GetModuleFileName(hModule, szPath, dwLength))) {
return(0);
}
p = szPath + dwLen;
while (p != szPath) {
if (TEXT('\\') == *--p) {
*(++p) = 0;
break;
}
}
return(p - szPath);

}
I get an exception...

Code:
DWORD dwPathSize;
LPTSTR path[512]={0};
dwPathSize = GetModuleDirectory(NULL,*path,512);


fzammetti wrote:
It's been posted before I think, but here's my version of that code, feel free to use it...
Code:
DWORD GetModuleDirectory(HMODULE hModule, LPTSTR szPath, DWORD dwLength) {

DWORD dwLen;
LPTSTR p;
if (0 == (dwLen = GetModuleFileName(hModule, szPath, dwLength))) {
return(0);
}
p = szPath + dwLen;
while (p != szPath) {
if (TEXT('\\') == *--p) {
*(++p) = 0;
break;
}
}
return(p - szPath);

}

ah ok, I should have declared:

path[512]=TEXT("\0");
LPTSTR path[512]={0};

That allocates an array of 512 pointers to strings and sets the first pointer to 0. It does not allocate an actual string array. This is correct:

TCHAR path[512];

Dan East