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
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to use unmanaged char arrays as class member?

How to use unmanaged char arrays as class member?

Scheduled Pinned Locked Moved Managed C++/CLI
helpdata-structurestutorialcombusiness
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thomas Freudenberg
    wrote on last edited by
    #1

    Hi, I have a problem when I add an unmanaged character array as an member to a managed class. Here's a simple example:

    __nogc class Foo
    {
    public:
    static void Test(char* sz)
    {}
    };

    __gc public class Bar
    {
    public:
    void TestFunc1()
    {
    char buffer[100];
    Foo::Test(buffer);
    }

    char anotherBuffer \_\_nogc\[100\];
    
    void TestFunc2()
    {
        Foo::Test(anotherBuffer);
    }
    

    };

    While there's no problem with Bar::TestFunc1, Bar::TestFunc2 won't compile. The error message is error C2664: cannot convert parameter 1 from 'char [100]' to 'char *'. The only difference is that in the first case the char array is allocated on the stack, while in the latter it's a member of the class.. However, if I change the call to

    void TestFunc2()
    {
        Foo::Test(&anotherBuffer\[0\]);
    }
    

    , I get the message error C2664: cannot convert parameter 1 from 'char __gc *' to 'char *'. Any help is appreciated. Regards Thomas


    Disclaimer:
    Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

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