-
Visual C++ Problem?
I am trying to use the _beginthreadex function instead of CreateThread (because I am more comfortable using older C functions), but even when I include <process.h> I get "...cpp(764) : error C2065: '_beginthreadex' : undeclared identifier"
So, I added the prototype myself:
unsigned long __cdecl _beginthreadex(void *, unsigned, unsigned (__stdcall *) (void *), void *, unsigned, unsigned *);
but then I started receiving...
...obj : error LNK2001: unresolved external symbol "unsigned long __cdecl _beginthreadex(void *,unsigned int,unsigned int (__stdcall*)(void *),void *,unsigned int,unsigned int *)" (?_beginthreadex@@YAKPAXIP6GI0@Z0IPAI@Z)
So, of course, I linked LIBCMT.LIB and also tried MSVCRT.LIB, but i still received the same "unresolved external symbol" error.
Is there something else I need to do?? (I am using Visual C++ 6.0 -- this is a non-MFC app I am working on)
Thanks
-
MSVC v6 help says _beginthreadex() is not supported / compatible for WIN98 or WIN2000 (only WIN95 and NT).
-
Thanks Novacain!
I don't have the MSDN help files since I just borrowed the Visual C++ CD from a friend...
I will have to use CreateThread() then...I was trying to avoid that since it leaks memory when used with old C functions
One problem though, I don't know an API that can work like the C function int tolower(int); Any suggestions??????
Thank you
-
write your own?! :)
something like
Code:
int MyToLower(char* string)
{
int len = ::lstrlen(string);
for(int i = 0; i < len; i++)
{
if(string[i] >= 'A' && string[i] <= 'Z')
{
string[i] -= 32;
}
}
return(1);
}
note: I didn't compile this code, I just wanted to give you the idea.
good luck!
U.
-
Uraldor Wrote:
<<<write your own?!
something like
code:
int MyToLower(char* string)
{
int len = ::lstrlen(string);
for(int i = 0; i < len; i++)
{
if(string[i] >= 'A' && string[i] <= 'Z')
{
string[i] -= 32;
}
}
return(1);
}>>>
Well, I could of done that myself (better yet, I could have used CharToLower), but that is not what the function tolower does. I included the prototype in my last post: int tolower(int);
An int, not a char* is passed to the function. Quite frankly, I don't know how it works. And since I am looking for a replacement...
tolower is able to handle this type of conditional statement:
char *Read;
int ArrayElement;
.
.
.
if(tolower(Read[ArrayElement]) == 'i')
{
// Do this
}
I was wondering if there is an API that does the same thing.
See what I mean?
Thanks
-
>>>
MSVC v6 help says _beginthreadex() is not supported / compatible for WIN98 or WIN2000 (only WIN95 and NT).
<<<
I'd never noticed that, so intrigued, I tried a little test...
Code:
#include <windows.h>
#include <stdio.h>
#include <process.h>
unsigned Counter;
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
printf( "i tråd...\n" );
while ( Counter < 1000000 )
Counter++;
_endthreadex( 0 );
return 0;
}
void main()
{
HANDLE hThread;
unsigned threadID;
printf( "lave tråd...\n" );
hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0,
&threadID );
WaitForSingleObject( hThread, INFINITE );
printf( "tælle skulle være 1000000; er -> %d\n", Counter );
CloseHandle( hThread );
}
... works fine with Win 2000, VC 6.0 Pro.
I bet you haven't changed your project settings to multithreaded...
-
>I don't know an API that can work like
>the C function int tolower(int);
>Any suggestions??????
Use the C function ? Who said you may not use it ?
-
nvoigt...wrote, "Use the C function ? Who said you may not use it ?"
"A thread that uses functions from the C run-time libraries should use the beginthread and endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called. "
http://students.cs.byu.edu/~cs345ta/...helpfiles.html
Is this still the case???? I assume it is
adrianxw wrote, "... works fine with Win 2000, VC 6.0 Pro.
I bet you haven't changed your project settings to multithreaded..."
Under Projects - Settings (or Alt F7) - Link - Object/library modules: I added the MSVCRT.LIB (and also tried LIBCMT.LIB) but I don't think that is what you meant ...So I will search the MSDN home page...
Thanks for the help
By the way, I meant CharLower not CharToLower :-p
Later on...
Ahhh...I found it...
"To find these options in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click Code Generation in the Category box. See the Use Run-Time Library drop-down box. "
http://msdn.microsoft.com/library/de...t.2c_2f.ld.asp
http://msdn.microsoft.com/library/de...d_programs.asp
Thanks Adrianxw, I had no idea
-
>>> Is this still the case???? I assume it is
I had a little discussion with Sunlight about this, and whilst he decided in theory it should no longer be necessary, we agreed that we would both continue using beginthreadex().
>>> Ahhh...I found it...
Sorry, I assumed you knew and had simply forgotten to do it. I should have given the sequence with my message.
Glad your okay now.