-
Oct 19th, 2014, 06:10 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Problems with device contexts in old DLL?
I'm still wrestling with the old DLL as posted here: http://www.vbforums.com/showthread.php?778541
The DLL implements sophisticated audio DSP and FFT functions that I cannot easily reproduce in any other way. The DLL works perfectly in a VB6 project. Many of the functions in the DLL are working fine in my VB.NET project, but the important ones that plot data to bitmaps are not working. The data cannot be returned in any other way. My best guess is that there are problems with handles and/or device contexts - some difference in the way these are handled between VB6 and VB.NET perhaps. I have reduced my code to the barest test program possible. This simply creates a DIB (Device Independent Bitmap) and then returns the size of the bitmap. The VB6 code works perfectly; the .Net code runs without error, displays something that look like it could be a pointer to a device context, but the second call returns only zeros. Here's the test code:
Code:
' VB6
Public Declare Function mmsCreateDIB Lib "SSTVENG.DLL" (ByVal width As Long, ByVal height As Long) As Long
Public Declare Function mmsGetDIBSize Lib "SSTVENG.DLL" (prc As Rect, ByVal hbsrc As Long) As Long
Type Rect
pLeft As Long
pTop As Long
pRight As Long
pBottom As Long
End Type
'Usage
Dim l As Long
l = mmsCreateDIB(320, 256)
MsgBox l
Dim l2 As Long
Dim rc As Rect
l2 = mmsGetDIBSize(rc, l)
MsgBox l2 & " : " & rc.pRight & " - " & rc.pBottom
Code:
' VB.NET
Public Declare Function mmsGetDIBSize Lib "SSTVENG.DLL" (prc As Rect, ByVal hbsrc As IntPtr) As Integer
Public Declare Function mmsCreateDIB Lib "SSTVENG.DLL" (ByVal width As Integer, ByVal height As Integer) As IntPtr
Structure Rect
Public pLeft As Integer
Public pTop As Integer
Public pRight As Integer
Public pBottom As Integer
End Structure
' Usage
Dim ptr As IntPtr = mmsCreateDIB(320, 256)
MessageBox.Show(ptr.ToString)
Dim rc As Rect
Dim iSize As Integer = mmsGetDIBSize(rc, ptr)
MessageBox.Show(iSize & " : " & rc.pRight & " - " & rc.pBottom)
Obviously I would never use this code just to create bitmaps; it's only an example of the kind of bitmap creation that must be used for the DLL to display its more sophisticated work. In case it helps, here's the documentation for the two functions used in the example code:
HBITMAP mmsCreateDIB(LONG width, LONG height)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Parameter]
width : DIB width
height : DIB height
[Return value]
Handle of the created DIB
[Remarks]
This function creates a 24-bit DIB and returns its handle.
[Note]
It is convenient for Microsoft Visual C++ developers to attach the returned HBITMAP to CBitmap class. For example, you can do it in the following way.
CBitmap m_bmpRX;
m_bmpRX.Attach(mmsCreateDIB(800, 616));
Do not forget to call m_bmpRX.DeleteObject(); to delete the calling bitmap at the exit of the application.
LONG mmsGetDIBSize(LPRECT prc, HBITMAP hbSrc)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Parameters]
prc : RECT-type pointer to the size
hbSrc : Handle of the DIB
[Return value]
Upper 16 bits : Height
Lower 16 bits : Width
[Remarks]
This function returns the pixel size of the specified DIB. If RECT-type pointer is assigned to prc, the information on the DIB pixel sizes is stored as follows.
rc.left = 0
rc.top = 0
rc.right = Width
rc.bottom = Height
If NULL is assigned to prc, the function does not store these values to prc.
Despite the major differences between VB6 and VB.NET, I find it surprising that this simple code fails, as it really only uses the DLL's own internal code. A device context to a bitmap is created and this is then passed to another function which should return a simple result. Where can the device context (if that is the problem) be corrupted?
Last edited by paulg4ije; Oct 19th, 2014 at 06:17 AM.
-
Oct 19th, 2014, 01:46 PM
#2
Thread Starter
Fanatic Member
Re: Problems with device contexts in old DLL?
I've started playing with marshalling (not sure I'm doing it right) and it hasn't helped. I've also tried changing the function definitions to use the format <DllImport("sstveng.dll")> but still not working.
Any ideas?
-
Oct 20th, 2014, 08:37 AM
#3
Thread Starter
Fanatic Member
Re: Problems with device contexts in old DLL?
Still trying to get this to work. If anyone wants to try out the code, the DLL is available here:
http://hamsoft.ca/pages/programmers.php
I know it's a big ask for someone to download the DLL and try my test code, but I'm getting desperate!
Any ideas would be much appreciated. Thank you.
Last edited by paulg4ije; Oct 20th, 2014 at 09:09 AM.
-
Oct 20th, 2014, 10:51 AM
#4
Thread Starter
Fanatic Member
Re: Problems with device contexts in old DLL?
I was slightly wrong in my summary: mmsCreateDIB returns a "HBITMAP" (as clearly shown in the documentation, duh!) which is a "handle to a bitmap", rather than a device context (subtle difference). It seems possible that that value is being corrupted in VB.Net. No luck with Marshalling so far. Still desperate for help!
EDIT:
Finally got it working. It seems the DLL functions don't like my rect "structure". Not sure why, but I can probably work around it.
Last edited by paulg4ije; Oct 20th, 2014 at 02:52 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|