Pointer value?

LittlePIC

New Member
Licensed User
Hi Basic4PPC Forum,

Just purchased,joined and not a .net programmer so sorry if this is a Noob question...been 10 years since Visual Studio 6 so very rusty :)

Trying to access real time PCM data from the Microphone...with no .net support have tried unmanaged(I think this is what you call it?) using Delcare type calls to winmm.dll eg Declare Function waveInOpen Lib "winmm.dll" Alias "waveInOpen" (ByRef...blah,blah...

All fine,receiving values,etc except accessing the buffer which holds the received data - it's returned as a pointer and not as a value?

To the best of my knowledge Pointers arn't supported in any form of VB but I could be wrong...I do remember a few .dlls which worked around this in VB6 but no idea in VB.net...

My question - how do I get the VALUE of the pointer? eg I receive back 20518416 as the value of the pointer,how do I convert to a Integer16 or whatever format I've requested?

Further background - Writting this code in #develop (vb.net) and would like to share once complete as a .dll for the whole community...hmmm...after I've got my prject completed and the bloody thing works :)

Many thanks...

LittlePIC
 

agraham

Expert
Licensed User
Longtime User
Although VB.NET can handle the IntPtr type it cannot dereference it whereas C# can manipulate and use pointers when code blocks are declared "unsafe".

If you insist on using VB.NET look at the Marshal class, especially Marshal.Copy, for methods that help bridge the managed and unmanaged worlds but be warned, there are loads of pitfalls!

There is a lot on MSDN about marshallling. Start looking here Consuming Unmanaged DLL Functions
 

LittlePIC

New Member
Licensed User
look like what I'm chasing...

Thanks Agraham,

I'll work through the marshal class - Yes this does look like what I'm chasing - thanks for the warning on using it...it's odd how difficult .Net makes calling OS dll's (unmanaged) considering this was previously standard practice!

Agree C# would be a better choice but if it's been 10 years since VB6,then it would be 15 years since learning C - never touched C# but sure I could pick it up...just wanted to get some runs on the board for this project and keep the learning curve to Basic4PPC(easy) and VB.Net(easy enough).Thinking out aloud - Wonder what would happen if I converted the dll code to C#, referenced the pointer back to a value, then converted the code to VB.Net?

Off topic - if anyone would like to write there own .dll's,I recommend #Develop (free and write in VB or C#) and use the Scrollbar example's posted elsewhere...I was surprised how easy it was to get going...could even add a 'Raise Event' from a Callback function when the audio buffer is full...this lets you add a Sub to your Basic4PPC program (<objectname_eventname>) which it triggered from the dll...

regards

LittlePIC
 

agraham

Expert
Licensed User
Longtime User
it's odd how difficult .Net makes calling OS dll's (unmanaged)
It's actually not difficult. Microsoft put a lot of effort into the parts of the .NET Framework for interacting with existing unmanaged code, particularly with COM and ActiveX components, so that previous coding investment could still be used. However you do need to know what you are doing. It is less well supported on the device, for space and performance reasons, than the desktop - but still pretty good in Compact Framework 2.0 and later.
Wonder what would happen if I converted the dll code to C#, referenced the pointer back to a value, then converted the code to VB.Net?
Can't be done. VB.NET doesn't have the corresponding functionality otherwise you could do it there.
 

LittlePIC

New Member
Licensed User
Beta WaveIn...

This 'capture' audio in realtime has been a bigger pain than I ever guessed...

Biggest issue is unexplained locking/crashing - which seemed to be from the GC (Garbage Collector)

I've Attached is a crude Beta if anyone can confirm stable?

No doc's should be easy enough to follow...

Just returning bytes for now...

regards

LittlePIC
 

Attachments

  • Wave_Beta.zip
    8.2 KB · Views: 195
Top