Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2004, 11:21 PM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Char in VC and String in VB ???

Hi Everybody
when i write DLL in VC
Code:
Void __stdcall WGS84TOVN99( char inStr[100], int j, char outStr[100] );
{
// Some command
}
I call it in VB:
Public Declare Function WGS84TOVN99 Lib Path+"\.dll" (ByRef InputLine As String, ByVal i As Long, outputLine As String)
Dim inStr as String
instr="My input String"
Dim outStr as String
Call WGS84TOVN99(inStr,1,outStr)
But when I debug in VC inStr not correct, that why program dump.
Can you help me
Thanks



 
Old February 16th, 2004, 03:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you need to use the BSTR type for strings in C/C++. BSTR is a Binary-Safe Unicode string. The length of the string is encoded in the first couple bytes of the string. That means that you can't use a fixed-size character array.

chars are 1-byte. Unicode (wide) characters are two bytes.

The string "Hello" as a char array will look like this (byte representation in hex):
Code:
 48  65  6c  6c  6f   00   00   00   00  ...  00
  |   |   |   |   |    |    |    |    |        |
 'h' 'e' 'l' 'l' 'o' '\0' '\0' '\0' '\0' ... '\0'
The same string as a BSTR will look like this:

Code:
00 00 00 05 00 48 00 65 00 6c 00 6c 00 6f
\_________/ \___/ \___/ \___/ \___/ \___/
 (length)    'H'   'e'   'l'   'l'   'o'

Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
char[...] or string.charAt(...) Ibn_Aziz Java Basics 1 June 14th, 2006 07:08 PM
getting the last CHAR of a string kondapally Crystal Reports 0 December 13th, 2004 03:39 PM
Replace or remove the last char from the string sabu21s XSLT 12 January 8th, 2004 05:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.