473,383 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Get string from structure filled by C++ functioncall

Hello @all

i need help with the following problem:

Im calling an unmanaged C++ DLL (TAPI32.dll) function (lineGetCallInfo) like
this:

Declare Function lineGetCallInfo Lib "tapi32.dll" (ByVal hCall As Integer,
ByRef lpCallInfo As LINECALLINFO) As Integer

Public Structure LINECALLINFO
Dim dwTotalSize As Integer
Dim dwNeededSize As Integer
Dim dwUsedSize As Integer
Dim hLine As Integer
Dim dwLineDeviceID As Integer
Dim dwAddressID As Integer
Dim dwBearerMode As Integer
Dim dwRate As Integer
Dim dwMediaMode As Integer
Dim dwAppSpecific As Integer
Dim dwCallID As Integer
Dim dwRelatedCallID As Integer
Dim dwCallParamFlags As Integer
Dim dwCallStates As Integer
Dim dwMonitorDigitModes As Integer
Dim dwMonitorMediaModes As Integer
Dim DialParams As LINEDIALPARAMS
Dim dwOrigin As Integer
Dim dwReason As Integer
Dim dwCompletionID As Integer
Dim dwNumOwners As Integer
Dim dwNumMonitors As Integer
Dim dwCountryCode As Integer
Dim dwTrunk As Integer
Dim dwCallerIDFlags As Integer
Dim dwCallerIDSize As Integer
Dim dwCallerIDOffset As Integer
Dim dwCallerIDNameSize As Integer
Dim dwCallerIDNameOffset As Integer
Dim dwCalledIDFlags As Integer
Dim dwCalledIDSize As Integer
Dim dwCalledIDOffset As Integer
Dim dwCalledIDNameSize As Integer
Dim dwCalledIDNameOffset As Integer
Dim dwConnectedIDFlags As Integer
Dim dwConnectedIDSize As Integer
Dim dwConnectedIDOffset As Integer
Dim dwConnectedIDNameSize As Integer
Dim dwConnectedIDNameOffset As Integer
Dim dwRedirectionIDFlags As Integer
Dim dwRedirectionIDSize As Integer
Dim dwRedirectionIDOffset As Integer
Dim dwRedirectionIDNameSize As Integer
Dim dwRedirectionIDNameOffset As Integer
Dim dwRedirectingIDFlags As Integer
Dim dwRedirectingIDSize As Integer
Dim dwRedirectingIDOffset As Integer
Dim dwRedirectingIDNameSize As Integer
Dim dwRedirectingIDNameOffset As Integer
Dim dwAppNameSize As Integer
Dim dwAppNameOffset As Integer
Dim dwDisplayableAddressSize As Integer
Dim dwDisplayableAddressOffset As Integer
Dim dwCalledPartySize As Integer
Dim dwCalledPartyOffset As Integer
Dim dwCommentSize As Integer
Dim dwCommentOffset As Integer
Dim dwDisplaySize As Integer
Dim dwDisplayOffset As Integer
Dim dwUserUserInfoSize As Integer
Dim dwUserUserInfoOffset As Integer
Dim dwHighLevelCompSize As Integer
Dim dwHighLevelCompOffset As Integer
Dim dwLowLevelCompSize As Integer
Dim dwLowLevelCompOffset As Integer
Dim dwChargingInfoSize As Integer
Dim dwChargingInfoOffset As Integer
Dim dwTerminalModesSize As Integer
Dim dwTerminalModesOffset As Integer
Dim dwDevSpecificSize As Integer
Dim dwDevSpecificOffset As Integer
End Structure

Dim strucCallinfo As LINECALLINFO
strcCallinfo.dwTotalSize = 1024
Dim ret As Integer = lineGetCallInfo(dwDevice, strucCallinfo)
'..... more code

Now the relevant fields in the structure are filled:

- dwCallerIDOffset
- dwCallerIDSize

Like I understand it, the structure has an address in memory (pointer). Now
I have to add the dwCallerIDOffset to the address.
I've done that in this way:

Dim CallingID as String

CallingID = GetStringFromStructure(strucCallinfo,
strucCallinfo.dwCallerIDOffset, strucCallinfo.dwCallerIDSize)

Private Function GetStringFromStructure(ByVal InputStructure As Object,
ByVal Offset As Integer, ByVal Length As Integer) As String
Dim RetString As String = ""
Dim ptrToStructure As IntPtr
Dim ptrToString As IntPtr

'// Allocate memory for a new pointer
ptrToStructure = Marshal.AllocHGlobal(Marshal.SizeOf(InputStructure ))

'// Marshal the structure to the pointer
Marshal.StructureToPtr(InputStructure, ptrToStructure, True)

'// Create a new pointer with the offset to the string
ptrToString = New IntPtr(ptrToStructure.ToInt32 + Offset)

'// Read the string from the new pointer with the specified length
RetString = Marshal.PtrToStringAnsi(ptrToString, Length)

'// Free allocated memory
Marshal.FreeHGlobal(ptrToStructure)

'// Return the extracted string
Return RetString

End Function
But everything i get is some ASCII-Salad like "°oæÃ*oæpæ"

What's wrong here? When i use the same function with an other structure
filled by a functioncall everything works fine :-(

So please help me, before it drives me crazy.

Jun 27 '08 #1
2 2081
"Assido" <As****@discussions.microsoft.comschrieb
Hello @all

i need help with the following problem:

Which OS do you use? It fails on a 64 bit OS. See changes below.
Im calling an unmanaged C++ DLL (TAPI32.dll) function
(lineGetCallInfo) like this:

Declare Function lineGetCallInfo Lib "tapi32.dll" (ByVal hCall As
Integer,
ByRef lpCallInfo As LINECALLINFO) As Integer
Declare Function lineGetCallInfo Lib "tapi32.dll" (ByVal hCall As
IntPtr, ByRef lpCallInfo As LINECALLINFO) As Integer
Dim hLine As Integer
Dim hLine As Intptr
At first glance I don't see an error in the code (only replace ToInt32
by ToInt64 on 64 bit OS (see IntPtr.Size)).

...Just one thing: Don't you have to reserve additional memory inside the
structure for the Strings to be returned (after dwDevSpecificOffset)?
You say "strcCallinfo.dwTotalSize = 1024", but the total size is less.
Maybe I'm wrong(?)
Armin

Jun 27 '08 #2
Hi Achim,

you are my hero! This is the result of crawling the sourcecode for mistakes
for days without taking a little break!

You are absoutly right! The CALLINFO-Structure has to contain a Bytearray to
reserve enough memory for the strings returned by the functioncall. I just
added
<System.Runtime.InteropServices.MarshalAs(Runtime. InteropServices.UnmanagedType.ByValArray, SizeConst:=2048)Dim ByteBuffer() As Byte

and it works!

Thank you so much!
"Armin Zingler" wrote:
"Assido" <As****@discussions.microsoft.comschrieb
Hello @all

i need help with the following problem:


Which OS do you use? It fails on a 64 bit OS. See changes below.
Im calling an unmanaged C++ DLL (TAPI32.dll) function
(lineGetCallInfo) like this:

Declare Function lineGetCallInfo Lib "tapi32.dll" (ByVal hCall As
Integer,
ByRef lpCallInfo As LINECALLINFO) As Integer

Declare Function lineGetCallInfo Lib "tapi32.dll" (ByVal hCall As
IntPtr, ByRef lpCallInfo As LINECALLINFO) As Integer
Dim hLine As Integer

Dim hLine As Intptr
At first glance I don't see an error in the code (only replace ToInt32
by ToInt64 on 64 bit OS (see IntPtr.Size)).

...Just one thing: Don't you have to reserve additional memory inside the
structure for the Strings to be returned (after dwDevSpecificOffset)?
You say "strcCallinfo.dwTotalSize = 1024", but the total size is less.
Maybe I'm wrong(?)
Armin

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Eli Daniel | last post by:
Hi, I'm new to Python. Can you please tell me if the following is possible. My users are using other scripting launguage to write scripts. They are used to write somthing like (keeping it...
1
by: Gil | last post by:
This is a question involving CORBA but the problem shows up using Sun C++. The problem doesn't occur with Visual C++ 6. I'm using a string in the following form in my CORBA IDL declaration so...
5
by: Flip | last post by:
I'm trying to create a form which a user can type out a key, and the CTRL-ALT-SHIFT keys are recognized (via ModifiedKeys object) and then pass the letter the user pressed to the windows API method...
4
by: Scott Lemen | last post by:
Hi, Some Win APIs expect a structure with a fixed length string. How is it defined in VB .Net 2003? When I try to use the FixedLengthString class I get an "Array bounds cannot appear in type...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
16
by: manstey | last post by:
Hi, If I have a string, how can I give that string name to a python object, such as a tuple. e.g. a = 'hello' b=(1234)
2
Soujiro
by: Soujiro | last post by:
typedef struct { int age; string name; } structure; int functionCall( map< char* , structure* >* map_o ) { map< char* , structure* >* map_op; map_op = map_o;
3
by: michelqa | last post by:
Hi, I already post a similar question last week without success. Ok I want to get the current text selection in a RICHEDIT control.. This can be easily done in C++ with EM_EXGETSEL message. I...
8
by: Andrew Smallshaw | last post by:
I'm working on a data structure that began life as a skip list derivative, but has evolved to the point that it now only has a passing resemblance to them. Each node of this structure has a few...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.