Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
T

ToolMaker2007

@ToolMaker2007
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • System.AccessViolationException - Returning from cpp dll
    T ToolMaker2007

    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:

    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.

    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.

    Managed C++/CLI csharp c++ help data-structures debugging

  • The process cannot access the file '' because it is being used by another process
    T ToolMaker2007

    Hi Guys, Mine was a dumbass developer faullt...well... din't realy knew once you create the file the creat method returns a stream :laugh: so yea just changed my line of code abit FileStream stream = fileInfo.Create(); stream.Close() Hope your problem is as simple as this...

    C# csharp help

  • The process cannot access the file '' because it is being used by another process
    T ToolMaker2007

    Hi, I get the same error. I'm using a FileInfo object with a file name passed to the constructor upon creating the FileInfo object. I check if the file exist and if so I delete it and recreat it. Al works fine first time but when I click on the button again to do the same functionality over again I get same error mentioned. The is NO close method on the FileInfo object nor Dispose. I tried the Refresh() in desprate attemps but still error. Please see a snipplet below: private void button2_Click(object sender, EventArgs e) { FileInfo fileInfo = new FileInfo(label2.Text + ".TMP"); if (fileInfo.Exists) { fileInfo.Delete(); } fileInfo.Create(); int y = 0; }

    C# csharp help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups