Valhalla Legends Forums Archive | .NET Platform | [C++.Net]Passing Arrays in VC++.Net

AuthorMessageTime
shout
I looked for a little bit on google but I could not find anything.

What I am trying to do is re-write my C# BnetHashing.dll library in C++, and have all the parameters and returns pointer-less.

So in C# for the decleration of the method I would have
[code]
public static byte[] HashData(byte[] Data)
{...}
[/code]
and from what I have pieced together, C++ would be something like
[code]
public:
      static System::Byte __gc* HashData(System::Byte __gc* data)
      {...}
[/code]

I could not find anything on returning. :'(
April 7, 2005, 12:55 AM
Myndfyr
[quote author=Shout link=topic=11206.msg107710#msg107710 date=1112835318]
I looked for a little bit on google but I could not find anything.

What I am trying to do is re-write my C# BnetHashing.dll library in C++, and have all the parameters and returns pointer-less.

So in C# for the decleration of the method I would have
[code]
public static byte[] HashData(byte[] Data)
{...}
[/code]
and from what I have pieced together, C++ would be something like
[code]
public:
       static System::Byte __gc* HashData(System::Byte __gc* data)
       {...}
[/code]

I could not find anything on returning. :'(
[/quote]

Well, in .NET, arrays are strongly typed.  I don't think you want to return a Byte*, either.

This is from the MSDN Guid.ToByteArray() method:
[code]
public: unsigned char ToByteArray()  __gc[];
[/code]

So what do I recommend for your conversion of the C# function signature?

[code]
typedef unsigned char byte;

public:
  byte __gc[] HashData(byte __gc[] data) const;
[/code]

The static modifier does something different in C/++ than it does in C#: specifically, it means that a value in a variable *inside a function* should be used across each function call.  Static in C# simply means that the function or field belongs to the type and not an instance of the type.

The HashData function should be able to be called in any of these ways:
[code]
hashedArray = MyClass::HashData(data);

MyClass obj;
hashedArray = obj::HashData(data);

MyClass* pobj = new MyClass;
hashedArray = pobj->HashData(data);
[/code]
April 7, 2005, 1:51 AM
shout
Fiddleing around, I found that this syntax works exactly how I wanted it to.
[code]
typedef unsigned char byte

public:
       System::Byte HashData(System::Byte __gc[] Data) __gc[];
[/code]
April 7, 2005, 2:41 AM
Adron
[quote author=MyndFyre link=topic=11206.msg107719#msg107719 date=1112838666]
The static modifier does something different in C/++ than it does in C#: specifically, it means that a value in a variable *inside a function* should be used across each function call.
[/quote]

The static modifier in C++ has many meanings. Your link describes them. Yes, as applied to variables defined in a function, it means that the data should be stored in the data segment instead of on the stack. That way it's instanced once for the entire program instead of once per copy of the function running.

When applied to variables defined in a class, it means the same thing - instanced once for the entire program instead of once per instance of the class. That way you don't need to create an instance of the class to be able to access it.

When applied to a function defined in a class, it means that the function doesn't access any members of the class that aren't static, i.e. that it doesn't need an instance of the class to function.

I'd say that "static" as used for class members in C++ corresponds very closely to the C# usage of static. Go ahead and use it :)
April 13, 2005, 7:38 PM

Search