Thread: Visual C++ Problem?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    39

    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
    Last edited by Echidna; 04-09-2002 at 11:48 PM.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    MSVC v6 help says _beginthreadex() is not supported / compatible for WIN98 or WIN2000 (only WIN95 and NT).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    39
    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

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    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.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    39
    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

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>>
    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...
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    >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 ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    39
    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
    Last edited by Echidna; 04-11-2002 at 12:36 PM.

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> 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.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual studio.net C++ Problem
    By Dina in forum C Programming
    Replies: 5
    Last Post: 07-19-2008, 02:34 PM
  2. Visual C++ Tool Problem
    By wolfban in forum Tech Board
    Replies: 2
    Last Post: 07-23-2005, 07:41 PM
  3. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM
  4. Visual Basic Adodc Problem
    By rahat in forum Windows Programming
    Replies: 1
    Last Post: 01-20-2002, 06:55 AM
  5. Microsoft Visual C++ compiler, cast problem?
    By jonnie75 in forum C Programming
    Replies: 5
    Last Post: 11-10-2001, 08:53 AM