Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2004

Tip: Looking for answers? Try searching our database.

Function Export

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JLW - 14 Jun 2004 14:26 GMT
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[i] = (int)input[i];
   }
}

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
William DePalo [MVP VC++] - 14 Jun 2004 16:51 GMT
> Here is my function in C++:
>
[quoted text clipped - 16 lines]
> 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
JLW - 16 Jun 2004 13:16 GMT
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

> > Here is my function in C++:
> >
[quoted text clipped - 32 lines]
> Regards,
> Will
Ronald Laeremans [MSFT] - 16 Jun 2004 21:35 GMT
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

>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
[quoted text clipped - 45 lines]
>> Regards,
>> Will

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.