Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7750887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:24:25+00:00 2026-06-01T11:24:25+00:00

I’m using pthread on Windows Form in Visual Studio 2008 Professional, But I’m getting

  • 0

I’m using pthread on Windows Form in Visual Studio 2008 Professional, But I’m getting the error in the line that I show in the example source. Probably because it’s C++/CLI because this usually work in regular classes. The problem is in this line:

((TestGUI*)context)->TestxFunc();

in the function StaticCallFunc

public ref class TestGUI : public System::Windows::Forms::Form {
        /...
    public:

void TestxFunc(std::string test, std::string test2){
        this->btn_next->Enabled = false;
        cout << "HI, Test: " << test << "," << " Test 2: " << test2 << endl;

 }

static void *StaticCallFunc(void *context){
    std::string test = "foo";
    std::string test2 = "bar";
    printf("\nStarting Thread");
    ((TestGUI*)context)->TestxFunc(); //Line with the error down.
    return 0;

} 

System::Void tester_Click(System::Object^  sender, System::EventArgs^  e) {
      pthread_t t;
      pthread_create(&t, NULL, &TestGUI::StaticCallFunc, this);
}

//...

error C3699: ” : cannot use this indirection on type ‘Test::TestxFunc’ 1>
compiler replacing ‘*’ with ‘^’ to continue parsing

error C2227: left of ‘->TestxFunc’ must point to
class/struct/union/generic type

what do I do to fix this? This call usually work on regular classes, but inside the Windows Form it really doesn’t

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:24:26+00:00Added an answer on June 1, 2026 at 11:24 am

    Since TestGUI is a CLI/C++ class, you should use the ^ not * to dereference its pointer, but thats not the only problem. It seems you want to execute a CLI/C++ class member method in a pthread. To make it work, you can try the following way:

    *Remove StaticCallFunc from TestGUI class and make it a global method.
    *To pass TestGUI pointer to an unmanaged function you can use gcroot. So define a container class e.g. PtrContainer which has gcroot as a member.

    //dont forget forward declerations
    void *StaticCallFunc(void *context); //forward decleration
    ref class TestGUI; //forward decleration
    
    //Define a simple argument class to pass pthread_create
    struct PtrContainer{
         gcroot<TestGUI^> guiPtr; //you need to include vcclr.h for this
    };
    

    When you bind to pthread_create you can use PtrContainer as the following:

    System::Void tester_Click(System::Object^  sender, System::EventArgs^  e) {
    
        //init. container pointer,
        //we use dynamically allocated object because the thread may use it after this method return
        PtrContainer* ptr = new PtrContainer;
        ptr->guiPtr = this;
    
        pthread_t t;
        pthread_create(&t, NULL, StaticCallFunc, ptr );
    }
    

    And you should delete the container pointer inside the driver method (StaticCallFunc) after you have done with it:

    void *StaticCallFunc(void *context){
        std::string test = "foo";
        std::string test2 = "bar";
        printf("\nStarting Thread");
        PtrContainer* ptr = reinterpret_cast<PtrContainer*>(context);
        ptr->guiPtr->TestxFunc(test, test2);
    
        //dont forget to delete the container ptr.
        delete ptr;
    
        return 0;
    }
    

    One more note; when you are accessing a .NET gui component in a multithread way, you must be careful to make calls to your controls in a thread-safe way.

    Edit: I have added the following complete source code which compiles and works under Visual Studio 11, Windows7.

    //sample.cpp
    
    #include <iostream>
    #include <string>
    #include <vcclr.h>
    #include <sstream>
    using namespace std;
    using namespace System;
    using namespace System::Windows::Forms;
    
    #include "pthread.h"
    #include <stdio.h>
    
    #define PTW32_THREAD_NULL_ID {NULL,0}
    #define int64_t _int64
    
    void *StaticCallFunc(void *context); //forward decleration
    ref class TestGUI; //forward decleration
    
    //Define a simple argument class to pass pthread_create
    struct PtrContainer{
        gcroot<TestGUI^> guiPtr; //you need to include vcclr.h for this
    };
    
    ref class TestGUI : public System::Windows::Forms::Form  
    {
    public:
        TestGUI(void) {
            this->Click += gcnew System::EventHandler(this, &TestGUI::tester_Click );
        }
    
        void TestxFunc(std::string test, std::string test2){
                cout << "HI, Test: " << test << "," << " Test 2: " << test2 << endl;
        }
    
        System::Void tester_Click(System::Object^  sender, System::EventArgs^  e) {
            //init. container pointer,
            //we use dynamically allocated object because the thread may use it after this method return
            PtrContainer* ptr = new PtrContainer;
            ptr->guiPtr = this;
    
            pthread_t t;
            pthread_create(&t, NULL, StaticCallFunc, ptr );
        }
    };
    
    void *StaticCallFunc(void *context){
        std::string test = "foo";
        std::string test2 = "bar";
        printf("\nStarting Thread");
        PtrContainer* ptr = reinterpret_cast<PtrContainer*>(context);
        ptr->guiPtr->TestxFunc(test, test2);
    
        //dont forget to delete the container ptr.
        delete ptr;
        return 0;
    }
    
    int main()
    {
        TestGUI^ testGui = gcnew TestGUI();
        testGui->ShowDialog();
        return 0;
    }
    

    Compiled with:

    /analyze- /clr /Od /nologo /MDd /Gm- /Fa".\Debug\" /I".." /Oy- /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Windows.Forms.dll" /Zc:forScope /Fo".\Debug\" /Gy- /Fp".\Debug\Debug.pch" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "CLEANUP_C" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /WX /errorReport:queue /GS /Fd".\Debug\" /fp:precise /FR".\Debug\" /W3 /Z7 /Zc:wchar_t /EHa 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.