Click here to Skip to main content
15,358,239 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: Display an image on the button. this image is not from resource but it is a image form a normal file Pin
Richard MacCutchan29-Oct-14 4:01
mveRichard MacCutchan29-Oct-14 4:01 
QuestionI need some help with c++ Pin
Member 1111856129-Sep-14 8:44
MemberMember 1111856129-Sep-14 8:44 
AnswerRe: I need some help with c++ Pin
Richard MacCutchan29-Sep-14 21:33
mveRichard MacCutchan29-Sep-14 21:33 
QuestionCoding music rhythms Pin
Navid Abyazi24-Sep-14 5:28
professionalNavid Abyazi24-Sep-14 5:28 
AnswerRe: Coding music rhythms Pin
Richard MacCutchan24-Sep-14 5:35
mveRichard MacCutchan24-Sep-14 5:35 
QuestionReverse No program Pin
Member 105011307-Sep-14 20:09
MemberMember 105011307-Sep-14 20:09 
AnswerRe: Reverse No program Pin
Richard MacCutchan7-Sep-14 21:23
mveRichard MacCutchan7-Sep-14 21:23 
QuestionSystem.AccessViolationException - Returning from cpp dll Pin
ToolMaker200716-Aug-14 4:25
MemberToolMaker200716-Aug-14 4:25 
Hi All,

Im sure this is easy. I'm forgotten to cpp. I need to write cpp wrapper over a dot net c# web service proxy class. I thought I would start with this basic tutorial...LOL already stuck.

Overview:
I have a Dotnet(c# managed) dll just adding some text to your input string:

C#
public class CSharpClass
    {
        public static byte[] Hello(byte[] name)
        {
            string s = ", hello from .NET!";
            byte[] helloPart = Encoding.ASCII.GetBytes(s);
            byte[] whole =
               new byte[name.Length + helloPart.Length];
            int i = 0;
            foreach (byte b in name)
            {
                whole[i++] = b;
            }
            foreach (byte b in helloPart)
            {
                whole[i++] = b;
            }
            return whole;
        }
    }


This get consummed by the CPP dll:


using namespace CSharpAssembly;

__declspec(dllexport) char* __stdcall Hello(char* name)
{
	int i = 0;
	while (*name != '\0')
	{
		i++;
		name++;
	}
	array<unsigned char>^ nameManArr = gcnew array<unsigned char>(i);
	name -= i;
	i = 0;
	while (*name != '\0')
	{
		nameManArr[i] = *name;
		name++;
		i++;
	}
	array<unsigned char>^ char8ManArr = CSharpClass::Hello(nameManArr);
	char*  char8UnmanArr = new char[char8ManArr->Length + 1];
	for (int i = 0; i < char8ManArr->Length; i++)
	{
		char8UnmanArr[i] = char8ManArr[i];
	}
	char8UnmanArr[char8ManArr->Length] = '\0';
	return char8UnmanArr;
}


I have a debug entry test command line app (C#) consuming the C++ dll.

C#
class DebugEntry
    {
        [DllImport("CppStdcallInerfaceWrapper2.dll",
              CharSet = CharSet.Ansi, CallingConvention =
                 CallingConvention.StdCall)]
        public static extern string Hello(string name);

        static void Main(string[] args)
        {
            string sd = Hello("MyName");
            System.Console.WriteLine();
            System.Console.ReadLine();
        }
    }


When I run the command line app I can debug through the cpp dll into the C# dll but when I return from the cpp dll I get error on returning to the debug commanline app.

I get error:
An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


I'm sure this is something simple?
AnswerRe: System.AccessViolationException - Returning from cpp dll Pin
Member 1048772028-Aug-14 21:45
MemberMember 1048772028-Aug-14 21:45 
Questionneed help with creating a clr dll Pin
neodeaths13-Aug-14 21:57
Memberneodeaths13-Aug-14 21:57 
AnswerRe: need help with creating a clr dll Pin
Richard MacCutchan13-Aug-14 22:26
mveRichard MacCutchan13-Aug-14 22:26 
QuestionHow to sound recorder c++ Pin
4manes6-Jul-14 22:58
Member4manes6-Jul-14 22:58 
AnswerRe: How to sound recorder c++ Pin
Richard MacCutchan7-Jul-14 2:46
mveRichard MacCutchan7-Jul-14 2:46 
QuestionDumb question about event arguments Pin
Member 1031630012-Jun-14 20:21
MemberMember 1031630012-Jun-14 20:21 
AnswerRe: Dumb question about event arguments Pin
John Schroedl13-Jun-14 8:05
professionalJohn Schroedl13-Jun-14 8:05 
GeneralRe: Dumb question about event arguments Pin
Member 1031630013-Jun-14 8:50
MemberMember 1031630013-Jun-14 8:50 
Ranthow to work with window in c++ Pin
TomTomtz30-May-14 12:02
MemberTomTomtz30-May-14 12:02 
GeneralRe: how to work with window in c++ Pin
Wes Aday30-May-14 12:29
professionalWes Aday30-May-14 12:29 
GeneralRe: how to work with window in c++ Pin
Richard MacCutchan30-May-14 22:08
mveRichard MacCutchan30-May-14 22:08 
GeneralRe: how to work with window in c++ Pin
WuRunZhe19-Jun-14 5:39
MemberWuRunZhe19-Jun-14 5:39 
QuestionCount from 1 to 1000 without using loops Pin
Amrit Agr26-May-14 0:09
MemberAmrit Agr26-May-14 0:09 
AnswerRe: Count from 1 to 1000 without using loops Pin
Richard MacCutchan26-May-14 0:42
mveRichard MacCutchan26-May-14 0:42 
GeneralRe: Count from 1 to 1000 without using loops Pin
Amrit Agr26-May-14 21:09
MemberAmrit Agr26-May-14 21:09 
GeneralRe: Count from 1 to 1000 without using loops Pin
WuRunZhe19-Jun-14 5:44
MemberWuRunZhe19-Jun-14 5:44 
GeneralRe: Count from 1 to 1000 without using loops Pin
Richard MacCutchan19-Jun-14 6:02
mveRichard MacCutchan19-Jun-14 6:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.