Function Export

  • Thread starter Thread starter JLW
  • Start date Start date
J

JLW

Here is my function in C++:

__declspec (dllexport) void CHARtoINT(char *input, int *output)
{
int length = strlen(input);

for (int i=0; i > length; i++)
{
output = (int)input;
}
}

Now, this function works fine if I declare it as a regular function and call
it from C++, but I need it exported and call from VB.NET.
Here's how it looks under VB.NET:

Public Shared SubCHARtoINT(ByVal input as string, ByRef output() as Integer)

And this crashes. I think it's to do with my ByRef call, but I need this
inorder for the function to work.

Thanks,
JLW
 
JLW said:
Here is my function in C++:

__declspec (dllexport) void CHARtoINT(char *input, int *output)
{
int length = strlen(input);

for (int i=0; i > length; i++)
{
output = (int)input;
}
}

Now, this function works fine if I declare it as a regular function and call
it from C++, but I need it exported and call from VB.NET.
Here's how it looks under VB.NET:

Public Shared SubCHARtoINT(ByVal input as string, ByRef output() as Integer)

And this crashes. I think it's to do with my ByRef call, but I need this
inorder for the function to work.


Disclaimer: I am happy to remain ignorant about all flavors of VB.

You talks about VB.Net so we are talking about managed code, yes?

If so, why do you use the old C-style null-terminated array of bytes instead
of the System::String class. If you switch to using strings then your
managed C++ code and your VB.Net code can both that common class.

If you are not targeting managed code then I _think_ (but I wouldn't bet
money on it) that "strings" in VB are BSTRs.

Regards,
Will
 
I actually only discovered std::string last night, and fell insantly inlove
with them. It looks like .NET String class is derived from the C++ String
class. I will be switching my code over to that, and I will let ya know if
it works. Ohh, hopefully one day I will learn C++ good enough, but till
then, gotta stick with what I know, VB.

Thanks again William,

JLW

William DePalo said:
JLW said:
Here is my function in C++:

__declspec (dllexport) void CHARtoINT(char *input, int *output)
{
int length = strlen(input);

for (int i=0; i > length; i++)
{
output = (int)input;
}
}

Now, this function works fine if I declare it as a regular function and call
it from C++, but I need it exported and call from VB.NET.
Here's how it looks under VB.NET:

Public Shared SubCHARtoINT(ByVal input as string, ByRef output() as Integer)

And this crashes. I think it's to do with my ByRef call, but I need this
inorder for the function to work.


Disclaimer: I am happy to remain ignorant about all flavors of VB.

You talks about VB.Net so we are talking about managed code, yes?

If so, why do you use the old C-style null-terminated array of bytes instead
of the System::String class. If you switch to using strings then your
managed C++ code and your VB.Net code can both that common class.

If you are not targeting managed code then I _think_ (but I wouldn't bet
money on it) that "strings" in VB are BSTRs.

Regards,
Will
 
Even just at the extremely fundamental level they are very different, .Net
strings are immutable and std::string is very much designed to be mutable.

Ronald Laeremans
Visual C++ team

JLW said:
I actually only discovered std::string last night, and fell insantly inlove
with them. It looks like .NET String class is derived from the C++ String
class. I will be switching my code over to that, and I will let ya know
if
it works. Ohh, hopefully one day I will learn C++ good enough, but till
then, gotta stick with what I know, VB.

Thanks again William,

JLW

William DePalo said:
JLW said:
Here is my function in C++:

__declspec (dllexport) void CHARtoINT(char *input, int *output)
{
int length = strlen(input);

for (int i=0; i > length; i++)
{
output = (int)input;
}
}

Now, this function works fine if I declare it as a regular function and call
it from C++, but I need it exported and call from VB.NET.
Here's how it looks under VB.NET:

Public Shared SubCHARtoINT(ByVal input as string, ByRef output() as Integer)

And this crashes. I think it's to do with my ByRef call, but I need this
inorder for the function to work.


Disclaimer: I am happy to remain ignorant about all flavors of VB.

You talks about VB.Net so we are talking about managed code, yes?

If so, why do you use the old C-style null-terminated array of bytes instead
of the System::String class. If you switch to using strings then your
managed C++ code and your VB.Net code can both that common class.

If you are not targeting managed code then I _think_ (but I wouldn't bet
money on it) that "strings" in VB are BSTRs.

Regards,
Will

 
Back
Top