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 274245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:34:48+00:00 2026-05-12T00:34:48+00:00

I am working on porting a large number of .h and .lib files from

  • 0

I am working on porting a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#.

Please, I know it’d be a lot easier to port the whole thing to .NET, but if I could I would. It’s 3rd party and all I have are .lib(no exports) and .h files to work with.

Everything has been going smoothly until I hit virtual functions and now I’m having some delegate issues.

Among the errors I’m getting are:

error C3756: ‘ThreadFunc’: delegate definition conflicts with an existing symbol
error C2079: ‘MyWrapTest::MyThreadWrap::m_threadAttr’ uses undefined class ‘MyWrapTest::MyThreadAttrWrap’
error C2664: ‘MyWrapTest::AutoPtr::AutoPtr(T *)’ : cannot convert parameter 1 from ‘MyWrapTest::MyThreadAttrWrap’ to ‘MyThread *’

For clarity, I’ll include the native code and the stuff I’m working on now. First, native code:

#ifndef MYTHREAD_HPP
#define MYTHREAD_HPP

#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#define STDCALL unsigned __stdcall
typedef unsigned (__stdcall *ThreadFunc)(void*);
#else
#define STDCALL void*
typedef void* (*ThreadFunc)(void*);
typedef unsigned int HANDLE ;
#endif
#include "generaltypes.hpp"

class MyThreadAttr;

class MyThread
{
public:
    MyThread(void);
    MyThread(MyThreadAttr * tta);
    virtual ~MyThread() {};
    virtual HANDLE start(ThreadFunc,void *, unsigned *);
    virtual int stop();
    static void wait(HANDLE);
#ifdef WIN32
    static void wait(HANDLE, int);// msec timeout required since 'cancelThread' is no-op  
#endif                            
    static void sleep(unsigned int);
    static int32 cancelThread(HANDLE hThread);  // no-op on Windows (returns -1)!
#ifndef WIN32
    static void setCancelStates(void);
    static void endProcess(); 
#endif

protected:
  MyThreadAttr * m_threadAttr;
  void setThreadAttr(MyThreadAttr * tta);
};

#endif

AND THE NEW STUFF I’M DEVELOPING:

#pragma once

#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#define STDCALL unsigned __stdcall
//typedef unsigned (__stdcall ThreadFunc)(Object^);
#else
#define STDCALL Object^
typedef unsigned int HANDLE;
#endif
#include "gentypes.hpp"
#include "AutoPtr.h"
#include "MyThread.hpp"

using namespace System;
using namespace System::Runtime::InteropServices;

namespace MyWrapTest
{

public delegate Object^ ThreadFunc(Object^ o);

ref class MyThreadAttrWrap;
//#include "MyThreadAttrWrap.h"

public ref class MyThreadWrap
{
public:
    MyThreadWrap(void)
    {
        AutoPtr<MyThread> m_NativeMyThread(new MyThread);
    };
    MyThreadWrap(MyThreadAttrWrap tta)
    {
        AutoPtr<MyThread> m_NativeMyThread(tta);
    };
    /*virtual ~MyThreadWrap(){};
    virtual HANDLE start(ThreadFunc,System::Object^, unsigned ^);
    virtual int stop();*/
    static void wait(HANDLE h)
    {
        m_NativeMyThread->wait(h);
    };
#ifdef WIN32
    static void wait(HANDLE h, int i) // msec timeout required since 'cancelThread' is no-op  
    {
        m_NativeMyThread->wait(h, i);
    };
#endif                            
    static void sleep(unsigned int i)
    {
        m_NativeMyThread->sleep(i);
    };
    static int32 cancelThread(HANDLE hThread);  // no-op on Windows (returns -1)!
#ifndef WIN32
    static void setCancelStates(void);
    static void endProcess(); 
#endif

protected:
  MyThreadAttrWrap m_threadAttr;
  void setThreadAttr(MyThreadAttrWrap tta);


private:
    AutoPtr<MyThread> m_NativeMyThread;
};
}
  • 1 1 Answer
  • 1 View
  • 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-05-12T00:34:48+00:00Added an answer on May 12, 2026 at 12:34 am

    Why do you define m_NativeMyThread in constructors again — this makes it local variable, you probably want this:

    MyThreadWrap()
        : m_NativeMyThread(new MyThread)
    {
    };
    

    Or

    MyThreadWrap()
    {
        m_NativeMyThread = AutoPtr<MyThread>(new MyThread);
    };
    

    I don’t usually use .Net, so I’m not sure about semantics of AutoPtr, but you want to change your member object, not create a local shadow.

    As for the error, here you create new local object of type AutoPtr and pass it one argument of type MyThreadAttrWrap.
    MyThreadWrap(MyThreadAttrWrap tta)
    {
    AutoPtr m_NativeMyThread(tta);
    };
    (I’m reading it as C++, correct me if .Net confuses things)

    What you want is to initialize m_NativeMyThread with new MyThread object that was constructed with unmanaged MyThreadAttr* object that was extracted from MyThreadAttrWrap that was passed in to your constructor.

    MyThreadWrap(MyThreadAttrWrap tta)
    {
        m_NativeMyThread = AutoPtr<MyThread>(new MyThread(tta.GetNativeAttr()));
    };
    

    BTW, be very carefull with ownership. From code you posted it is unclear if MyThread owns MyThreadAttr or if it is owned externally. And AutoPtr owns its enclosed pointer (if it at all named properly).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on porting over a database from a custom MSSQL CMS to
I'm working on porting an app from WPF to Silverlight. The app uses custom
I'm porting some (working) code from Linux to Windows 8. I'm using DDK. typedef
I am working on porting an application from WPF to a Windows 8 App.
I am working on porting a Java codebase to Cocoa/Objective-C for use on desktop
I am working on porting code from JAVA to C#, and part of the
So, I'll be soon working on porting two APIs (C++ and C++/CLI) to use
I'm working on porting some ancient code (10.2 era) from NSCoding/plist based archiving to
I am working on porting a legacy ISAPI DLL (it is an ISAPI extension,
Some working C++ code that I'm porting from Linux to Windows is failing on

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.