I desperately need help on data type conversions. I am working on converting a set of codes in Visual Basic to C but i'm faced with a lot of problems dealing with strings. Can anyone help me out here? Below is the code I have in Visual Basic.

Private Function RegGetStringValue(ByVal hKey As Long, _
                                   ByVal sValue As String, _
                                   dwDataSize As Long) As String

   Dim sDataRet As String
   Dim dwDataRet As Long
   Dim success As Long
   Dim pos As Long
  'returns number of spaces based on dwDataSize
   sDataRet = Space$(dwDataSize)

  'get the size of the null terminating char
   dwDataRet = Len(sDataRet)
   success = RegQueryValueEx(hKey, sValue, _
                             ByVal 0&, dwDataSize, _
                             ByVal sDataRet, dwDataRet)
   If success = ERROR_SUCCESS Then
      If dwDataRet > 0 Then
         pos = InStr(sDataRet, Chr$(0))
         RegGetStringValue = Left$(sDataRet, pos - 1)
      End If
   End If
End Function

*Has A Headache Just Thinking About It*

Understand, that this will be the bloodiest, most brutal war in computer history.... as long as you are aware of this....Seeing That VB Misses A HUGE number of things that C is able to accomplish. You don't have pointers, you don't have structs or unions... user defined types... sure. Then you have to take into account that strings in VB are NOT (well they are internally, but not in any helpful form to you) array's of type char. However, here is how you can cast things in VB:

Cint(expression) casts expression to an integer. If expression is a floating-point value or a currency value, it is rounded. If it is a string that looks like a number, it is turned into that number and then rounded if necessary. If it is a Boolean value of True, it becomes a -1. False becomes 0. It must also be within the range that an integer can store.

Cbyte(expression) casts expression to a byte value provided that expression falls between 0 and 255. expression should be numeric or something that can be cast to a number.

Cdbl(expression) casts expression to a double. expression should be numeric or something that can be cast to a number.

Csng(expression) casts expression to a single. It works like Cdbl(), but must fall within the range represented by a single.

Cbool(expression) casts expression to a Boolean value. If expression is 0, the result is False. Otherwise, the result is True. expression should be numeric or something that can be cast to a number.

Ccur(expression) casts expression to a currency value. expression should be numeric or something that can be cast to a number.

Cdate(expression) casts expression to a date value. expression should be numeric or something that can be cast to a number, or a string of a commonly used date format.
DateValue(expression) or TimeValue(expression) can also be used for this.

Cstr(expression) casts expression to a string. expression can be any kind of data.

Good Luck To you...

Thanks for replying...that certainly helped me in understanding the VB codes..

But what i am actually looking for is data type conversions in C :o
What i need is exactly what you posted...but in C >_<

By the way...i apologise for the duplicate post...wanted to look for help in both places :sad:

You aren't the first to duplicate post ;)

Ok, In C, you can CAST a Variable with this syntax:


So, For Example, Let's say that you want to take the floating point number x, and use it as an integer:

float x = 1.1;
int y = 2;
answer = (int)x + y;

Now, I try not to code in C much, and my syntax could be a bit off... but that should took the floating point variable x, and cast it as an integer, and add it with y. So, you can cast any type as far as I know. The types that I know of are:

long double

Hope this helps.... and let me know if you need anything else. I'll also talk to an admin about WHERE this thread should go.... it seems to me it's a vb app right?

Thanks for the help~!Really appreciate it~

ya that is a vb app...but i'm actually looking for help in C...because my objective is to get that chunk of code converted to C.
i'm kinda confused on where i should post the thread in so i decided to create a post in each of them. :sad: