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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:56:28+00:00 2026-06-15T06:56:28+00:00

I am trying to get some C++ code working under C#. I have been

  • 0

I am trying to get some C++ code working under C#. I have been trying to follow tutorials online all over the place without any luck compiling or executing the code.

I’ve written a basic C++ class that compiles to a .dll, and a C# console application.
– I’ve changed the platform toolset to v100 on the C++ dll
– I’ve added a reference to the dll in my C# application

Note I am trying to use a C++ class, not C++ static functions… on to the code!

// CTrans.h
#pragma once

#include "windows.h"

using namespace System;

namespace CTrans {

    public ref class CTransClass
    {
    public:
    System::String^ helloWorld();
    };
}

// CTrans.cpp
// This is the main DLL file.
#include "stdafx.h"
#include "CTrans.h"

String^ CTrans::CTransClass::helloWorld()
{
    return gcnew System::String("Hello World!");
}

// Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CTWrapper
{
    class Program
    {
        static void Main(string[] args)
        {
            unsafe
            {
                CTrans.CTransClass trans = new CTrans.CTransClass();
                String tmp = trans.helloWorld();
            }
        }
    }
}

Error: http://sumarlidason.com/Capture.PNG

edit: removed niceties, add screenshot of error.

  • 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-15T06:56:30+00:00Added an answer on June 15, 2026 at 6:56 am

    Did you try adding a “using CTrans;” to the top of the Program.cs using block?

    Check to make sure the assemblies are compiled with the same architecture (x86/x64), and that there are no other related warnings in the Error List.

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

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
I have some really complicated legacy code I've been working on that crashes when
I'm trying to get some code working that a previous developer has written. Yep,
I am trying to get some code working from an example I came across.
Ok, so I'm trying to get some UDP code working and I'm barely green
I'm trying to get some simple code working to log the pitch, roll, and
I'm trying to get some image processing code working in MS VC++ 2010 express.
I've been working with the Google WebGL Globe and trying to get some rudimentary
I’m trying to get some code working using OData. The following bit of code
I'm trying to get some RJS code written with prototype and Rails 2.3.11 to

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.