Allocating Memory and Structures. 
Author Message
 Allocating Memory and Structures.

Hello

I am writing and Tapi phone program, which is a softphone basically.  This
was original developed in VB5 however I wish move it to vb .net.  I am not
using the convert utility as the design of the program has changed. Normally
I would use a varptr to get a memory address of a structure.  I can not use
this is vb .net.

I have attached some sample code, which I think should allocate the memory
and return a pointer ,however it does not work, if just returns a negative
number.  See if you can whats wrong with it.

API First

Declare Function lineGetDevCaps Lib "tapi32.dll" Alias "lineGetDevCapsA" _
(ByVal hLineApp As Integer, _
ByVal dwDeviceID As Integer, _
ByVal dwAPIVersion As Integer, _
ByVal dwExtVersion As Integer, _
ByRef lpLineDevCaps As LINEDEVCAPS) As Integer

The code now , m_lineCaps is dclared as dim m_lineCaps as LINEDEVCAPS

' make it big enough
m_LineCaps.dwNeededSize = Len(m_LineCaps) + 3072

Dim fPtr As IntPtr = Marshal.AllocHGlobal(m_LineCaps.dwNeededSize)
Marshal.StructureToPtr(m_LineCaps, fPtr, True)
result = 0
result = lineGetDevCaps(m_hLineApp, i, usingAPI, 0, m_LineCaps)
Marshal.FreeHGlobal(fPtr)

result just ends up with a negative number, it should be a zero.  The first
thing that confuses me is on the linegetdevcapscode should I have the
m_lineCaps or the pointer,  If I need the pointer then what should the API
declartion have.

Memory allocation seems to be the biggest pain out at the moment.  If it
fails the only other thing I can to is write it in VC++.

Thanks for your help in Advance.
Mr Kalpesh Modha



Sun, 06 Mar 2005 04:49:59 GMT  
 Allocating Memory and Structures.
Kalpesh,

Quote:
>result just ends up with a negative number, it should be a zero.  The first
>thing that confuses me is on the linegetdevcapscode should I have the
>m_lineCaps or the pointer,  If I need the pointer then what should the API
>declartion have.

The pointer. Change the declaration to

..., ByVal lpLineDecCaps As IntPtr) As Integer

Also, the docs say you should set LINEDEVCAPS.dwTotalSize before the
call, you're just setting dwNeededSize.

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Sun, 06 Mar 2005 06:14:47 GMT  
 Allocating Memory and Structures.
thanks very much for that.

One more question, on the LINEDEVCAPS structure, what does type GUID convert
to in VB.net,  Like DWORD is an Integer.

Thanks
Kalpesh Modha

Quote:
> Kalpesh,

> >result just ends up with a negative number, it should be a zero.  The
first
> >thing that confuses me is on the linegetdevcapscode should I have the
> >m_lineCaps or the pointer,  If I need the pointer then what should the
API
> >declartion have.

> The pointer. Change the declaration to

> ..., ByVal lpLineDecCaps As IntPtr) As Integer

> Also, the docs say you should set LINEDEVCAPS.dwTotalSize before the
> call, you're just setting dwNeededSize.

> Mattias

> ===

> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.



Sun, 06 Mar 2005 15:04:27 GMT  
 Allocating Memory and Structures.
Kalpesh,

Quote:
>One more question, on the LINEDEVCAPS structure, what does type GUID convert
>to in VB.net,  Like DWORD is an Integer.

System.Guid

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Sun, 06 Mar 2005 22:12:29 GMT  
 Allocating Memory and Structures.
thanks


Quote:
> Kalpesh,

> >One more question, on the LINEDEVCAPS structure, what does type GUID
convert
> >to in VB.net,  Like DWORD is an Integer.

> System.Guid

> Mattias

> ===

> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.



Sun, 06 Mar 2005 23:29:38 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. PictureClip unable to allocate internal picture structure

2. allocating memory

3. Allocating memory

4. How to set free memory allocated by an array dynamically created

5. Allocate Memory

6. Question: Accessing memory allocated in DLL

7. Allocating memory

8. Allocating Memory in a Called Function

9. Accessing another Apps allocated memory (w/vb)

10. How much memory I can allocate?

11. Memory allocated by parameters

12. Internet Transfer Control Causes Allocated Memory To Increase

 

 
Powered by phpBB® Forum Software