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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:17:22+00:00 2026-05-27T04:17:22+00:00

So as the title states, I am looking to pass an object that is

  • 0

So as the title states, I am looking to pass an object that is defined in an unmanaged C++ project into a managed C++/CLI project (both projects are in the same solution) while still being able to access the same methods as in the unmanaged C++ project.

This object is a class which imports functions from a separate unmanaged C++ dll (not in the same project or solution) through the means of using typedef‘s as shown below (excerpt of header):

#pragma unmanaged    

typedef BOOL (WINAPI *someBoolFunc) (DWORD Name, DWORD Flags, TCHAR* Text);

class INeedThisClass
{
public:
    INeedThisClass();
    ~INeedThisClass();

    someBoolFunc BoolFunc;
}; 

extern INeedThisClass ReallyNeedThisClass;

I would really like to be able to access the externed object ReallyNeedThisClass from within my managed code by just only passing the object. By having this object I wish to access it’s methods through ReallyNeedThisClass->BoolFunc. What is the best way of accessing this object from my managed code?

EDIT: I’ve been thinking maybe there is a way of using a property to “Get” the object from the unmanaged code and then “Set” the same object in the managed code. Could this be a proper angle to approach this issue from? I’ve cleaned up the question a bit to get rid of useless details.

UPDATE: I’ve made progress on this using a wrapper for the unmanaged C++ code, but of course there are still problems. Using the above class as an example here, I will show you what I have managed to do up until now.

Project 1: Unmanaged C++ class (example above)

Project 2: Managed C++/CLR wrapper class (example below)

Wrapper.h:

#pragma once

#include "INeedThisClass.h" //Unmanaged class INeedThisClass

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

namespace INeedThisClassWrapper
{
    public ref class INTC
    {
    public:
        INTC(void);
        virtual ~INTC(void);

        delegate bool BoolFunc(UInt32 Name, UInt32 Flags, String^ Text);

    private:
        INeedThisClass *ReallyNeedThisClass;
    };
}

Wrapper.cpp:

#include "Stdafx.h"
#include "Wrapper.h"
using namespace INeedThisClassWrapper

#include <msclr/marshal.h>
using namespace msclr::interop;

INTC::INTC(void)
{
    ReallyNeedThisClass = new INeedThisClass();
}

INTC::~INTC(void)
{
    if (ReallyNeedThisClass)
    {
        delete ReallyNeedThisClass;
        ReallyNeedThisClass = NULL;
    }
}

bool INTC::BoolFunc(UInt32 Name, UInt32 Flags, String^ Text)
{
    return ReallyNeedThisClass->BoolFunc;
}

Now I am receiving errors from the compiler stating:

error C2065: 'WINAPI': undeclared identifier
error C2065: 'someBoolFunc': undeclared identifier
error C4430: missing type specifier - int assumed. Note C++ does not support default-int

Any ideas?

  • 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-05-27T04:17:22+00:00Added an answer on May 27, 2026 at 4:17 am

    First, you have to export INeedThisClass from unmanaged dll and import from managed one.

    //unmanaged header
    
    #if UNMANAGED_COMPILE_DEFINITION
    #define EXPORT_OR_IMPORT __declspec(dllexport)
    #else
    #define EXPORT_OR_IMPORT __declspec(dllimport)
    #endif
    
    class EXPORT_OR_IMPORT INeedThisClass
    {
    public:
        INeedThisClass();
        ~INeedThisClass();
    
        someBoolFunc BoolFunc;
    };
    

    Also unmanaged dll must be compiled with UNMANAGED_COMPILE_DEFINITION preprocessor definiton.

    Second, remove extern INeedThisClass ReallyNeedThisClass; you don’t need it. Because ReallyNeedThisClass is a member of wrapper class already.

    Third, you need to marshal System::String^ to TCHAR* in order to call BoolFunc

    Forth, I do not remember but if you include “Windows.h” or “Winnt.h”, the error about WINAPI will be gone.

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

Sidebar

Related Questions

As the title states, I am looking for something, that will help me automate
As the title states, I am using devise. I came upon this link that
As the title states, if I don't clean my project before building, neither the
Just as the title states, I'm looking to display a blank template graph (by
As the title states, I'm looking for a basic (working) tutorial of Java code
As the title states, I'm looking for a lightweight Rails 3(.1) WYSIWYG editor. I
As the title states, I am looking for a java collection keeping only the
As the title states, we're looking for a way to access a .NET 3.5
Just as the title states, is there a jQuery plugin effect that will allow
As the title states, I'm trying to resize a Texture2D before even considering SpriteBatch.Draw()

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.