I didn't realize that string variable was destroyed after the function creating the thread returns. Now my DLL works great. Frankie, thank you so much.
pcname
Posts
-
How to correctly pass a LPCSTR type parameter to a thread in DLL? -
How to correctly pass a LPCSTR type parameter to a thread in DLL?no compiler error. when I calling the DLL from VBA, the function just cannot pass a file path to the thread. File path in thread displayed as "s", "c", etc.
-
How to correctly pass a LPCSTR type parameter to a thread in DLL?"flt" is the file path from VBA. it's "C:\Downloads\HornSound.wav." Sorry, it's my mistake. the "loct" in MessageBox should be replaced with "flt". I spent some time try to figure it out. So as I said, I added " MessageBox(NULL, flt, "Message1", NULL); " before "CloseHandle(hThread);". both messagebox can correctly display my file path "C:\Downloads\HornSound.wav." I also found if I replaced "MessageBox" with "Sleep(3000)" before "CloseHandle(hThread);" MessageBox in thread can correctly display my file path "C:\Downloads\HornSound.wav." if I add nothing and just removed "CloseHandle(hThread);", MessageBox in thread can also correctly display my file path "C:\Downloads\HornSound.wav." It seems I cannot close handle right after CreateThread. but that can cause memory leak?
-
How to correctly pass a LPCSTR type parameter to a thread in DLL?No, my function is not a Unicode function. my file path is C:\Downloads\HornSound.wav. I found if I added the following " MessageBox(NULL, loct, "Message1", NULL); " before "CloseHandle(hThread);". Both MessageBoxes (both in the function and in the thread) can correctly display the file path. But if I removed "MessageBox" in the function, then the MessageBox in the thread cannot correctly display the file path. What is the problem?
-
How to correctly pass a LPCSTR type parameter to a thread in DLL?MessageBox display is not file path, instead it showed something "s" or "c", "7". this is what I don't understand.
-
How to correctly pass a LPCSTR type parameter to a thread in DLL?I wrote a DLL with VC6.0. I want to pass a LPCSTR type parameter (file path) to a thread. Here is the code: DWORD WINAPI ThreadFunc(LPVOID lpParam) { char* fileLoct = (char*)lpParam; MessageBox(NULL, fileLoct, "Message", MB_OK | MB_ICONINFORMATION); return 0; } void __stdcall StartThread(LPCSTR flt) { HANDLE hThread; hThread = CreateThread(NULL, 0, ThreadFunc, (void *)flt, 0, NULL); CloseHandle(hThread); } I tested it with MessageBox and found the path was not correct at all. How to correctly pass a LPCSTR type parameter to a thread in DLL? Thank you.
-
Is there another ways to get file date stamp?Thanks. I used GetFileTime. But I got another problem.Following is my code: TCHAR FilePath[MAX_PATH]; TCHAR NewPath[MAX_PATH]; WIN32_FIND_DATA fd; FILETIME mtime, local; SYSTEMTIME st; sprintf(FilePath, "%s\\*.*", strpath); HANDLE hFind = FindFirstFile(FilePath, &fd); if (hFind == INVALID_HANDLE_VALUE) return; do { if (fd.cFileName[0] != '.') { if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { sprintf(NewPath, "%s\\%s", strpath, fd.cFileName); Findfiles(NewPath); } else { GetFileTime(hFind, NULL, NULL, &mtime); FileTimeToLocalFileTime( &mtime, &local ); FileTimeToSystemTime(&local, &st); CString time; time.Format("%02d/%02d/%04d", st.wMonth, st.wDay, st.wYear); AfxMessageBox(time); } } } while (FindNextFile(hFind, &fd)); FindClose(hFind); But my file last modofied time is 9/5/2006. The Time always dispalyed as 12/24/18186. what is wrong? Thanks a lot.
-
Is there another ways to get file date stamp?I used the following code to get file date time stamp. CFileFind ff; CFileStatus status; xxxxxx; xxxxxx; CString strFilePath = ff.GetFilePath(); CFile::GetStatus(strFilePath, status); CTime Ftime = status.m_mtime; Ftime is CTime object. But CTime has limit (Year <=2037 or so) is there another ways to get file date time stamp except CFile::GetStatus? Thanks