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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:35:36+00:00 2026-05-15T20:35:36+00:00

I am wrote a visual c++ win32 console app, and i wrote it and

  • 0

I am wrote a visual c++ win32 console app, and i wrote it and tested it in

win32 console project

. then i switch to

win32 project

and imported all the source files and created a dll for it. by mark the class i want to export as

#define DllExport   __declspec( dllexport )

class DllExport theClass {
} 

it works and the dll is generated. then i created a another c# project and want to add the dll to the project. by reference->add reference-> browser. then i select that dll.
then it is gives me an error

a reference to the ”””’.dll could
not be added. please make sure that
the file is accessible, and that is a
valid assembly or com component.

anyone knows where i did wrong to generate/import the dll?

thanks

  • 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-15T20:35:36+00:00Added an answer on May 15, 2026 at 8:35 pm

    The Add Reference dialog can only work for DLLs that contain metadata (managed code) or a type library (a COM server). Your DLL doesn’t fit that bill, you can only use the [DllImport] attribute in C# code to use the P/Invoke marshaller to call an unmanaged DLL entrypoint.

    That can not be a native C++ class, like you are trying to do, there is no reliable mechanism for managed code to allocate unmanaged memory and call the constructor (and destructor) of a native C++ class. Short from the difficulty of finding the constructor and destructor code, there is no way for the P/Invoke marshaller to know the size of the object. The C++ language doesn’t generate the metadata necessary to know this required information.

    If you want to pursue P/Invoke then write an plain global function, decorated with extern “C”, __declspec(dllexport) and (optionally) __stdcall.

    If you want to export a C++ class then the only avenue is using the C++/CLI language and write a “ref class” wrapper for the native C++ class.

    Or you could write a COM coclass, the universal glue in Windows. Very well supported by .NET, probably not something you want to pursue if you never wrote COM code before. ATL is the best way to get one going.

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

Sidebar

Related Questions

I wrote a console application project. When I debug it through visual studio 2010
I wrote a simple console app in Visual Studio 10 on a Windows 7
Using Visual Studio 2005, I wrote a simple DLL in C that uses the
I wrote a C++ DLL and it has been compiled. It requires Visual C++
I created win32 console application in vs2010 (without select the option of precompiled header).
When developing a Win32 Application (non-console application) in Visual Studio 2005, is there any
From within a C# application(Visual Studio 2008) i am calling a win32 dll using
I wrote and tested some code in a Windows XP (Qt 4.7.2) using Visual
I developed a logger for testing our modules in c++, Win32 console, visual studio(Windows)
I wrote an app in Visual Studio and is about 20k+ lines, but I

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.