Hi All,
I am upgrading my app (working well with VB6) to VB.NET. It sends MIDI
messages using the API multimedia winmm.dll .
These functions are declared:
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As
Integer, _
ByVal uResolution As Integer, ByVal lpFunction As MidiPlayDelegat e, _
ByVal dwUser As Integer, ByVal uFlags As Integer) As Integer
Delegate Function MidiPlayDelegat e(ByVal lTimerID As Integer, ByVal dwMsg As
Integer, _
ByVal dwUser As Integer, ByVal lParam1 As Integer, ByVal lParam2 As
Integer) As Integer
and a function MidiPlay is available:
Public Function MidiPlay(ByVal lTimerID As Integer, ByVal dwMsg As Integer,
_
ByVal dwUser As Integer, ByVal lParam1 As Integer, ByVal lParam2 As
Integer) As Integer
...
lRet = midiOutShortMsg (hMidiOut, mididata)
...
End Function
----------------------------------------------------------------------------
-----
A MIDI port is opened by a call to midiOutOpen, then a timer is started by
the statement
lTimerID = timeSetEvent(1, 1, AddressOf MidiPlay, 0, 1)
which runs in its own thread.
On each time event the call back function MidiPlay is called, which in turn
sends the MIDI data through
lRet = midiOutShortMsg (hMidiOut, mididata)
When the program is run a System.NullRefe renceException occurs in an Unknown
Module (the
MidiPlayDelegat e, I guess), because
"Object reference not set to an instance of an object"
Which object reference should be set?
Thank you for your help,
ReinierVDW 2 2922
Your problem is probably on this line:
lTimerID = timeSetEvent(1, 1, AddressOf MidiPlay, 0, 1)
The delegate created by the AddressOf MidiPlay statement does not have any
references to it so it will be garbage collected. If you need a delegate
that will stick around for future callbacks you must keep a live reference
to it. For example:
in your class create a class level delegate variable
Private m_TimerCallback as MDIPlayDelegate
then in the code that sets up the timer callbacks:
m_TimerCallback = New MDIPlayDelegate (AddressOf MDIPlay)
lTimerID = timeSetEvent(1, 1, m_TimerCallback , 0, 1)
now the delegate will stick around as long as your class does.
"R. van der Welle" <r.************ @onzin.freeler. nl> wrote in message
news:eA******** ******@tk2msftn gp13.phx.gbl... Hi All,
I am upgrading my app (working well with VB6) to VB.NET. It sends MIDI messages using the API multimedia winmm.dll . These functions are declared:
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Integer, _ ByVal uResolution As Integer, ByVal lpFunction As MidiPlayDelegat e, _ ByVal dwUser As Integer, ByVal uFlags As Integer) As Integer
Delegate Function MidiPlayDelegat e(ByVal lTimerID As Integer, ByVal dwMsg
As Integer, _ ByVal dwUser As Integer, ByVal lParam1 As Integer, ByVal lParam2 As Integer) As Integer
and a function MidiPlay is available: Public Function MidiPlay(ByVal lTimerID As Integer, ByVal dwMsg As
Integer, _ ByVal dwUser As Integer, ByVal lParam1 As Integer, ByVal lParam2 As Integer) As Integer ... lRet = midiOutShortMsg (hMidiOut, mididata) ... End Function --------------------------------------------------------------------------
-- -----
A MIDI port is opened by a call to midiOutOpen, then a timer is started by the statement lTimerID = timeSetEvent(1, 1, AddressOf MidiPlay, 0, 1) which runs in its own thread. On each time event the call back function MidiPlay is called, which in
turn sends the MIDI data through lRet = midiOutShortMsg (hMidiOut, mididata)
When the program is run a System.NullRefe renceException occurs in an
Unknown Module (the MidiPlayDelegat e, I guess), because "Object reference not set to an instance of an object"
Which object reference should be set?
Thank you for your help,
ReinierVDW
* "R. van der Welle" <r.************ @onzin.freeler. nl> scripsit: A MIDI port is opened by a call to midiOutOpen, then a timer is started by the statement lTimerID = timeSetEvent(1, 1, AddressOf MidiPlay, 0, 1) which runs in its own thread. On each time event the call back function MidiPlay is called, which in turn sends the MIDI data through lRet = midiOutShortMsg (hMidiOut, mididata)
When the program is run a System.NullRefe renceException occurs in an Unknown Module (the MidiPlayDelegat e, I guess), because "Object reference not set to an instance of an object"
Which object reference should be set?
Don't forget to save a reference to the delegate!
Simple sample written by Armin Zingler:
\\\
dim o as CallBack
o = new CallBack(addres sof CallBackSub)
'...
private sub CallBackSub
end sub
///
--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Terrence |
last post by:
I am doing some of the C# walkthroughs to transition from
VB to C#. When I try to execute
static void Main()
{
Aplication.Run(new Form1())
}
I raise a 'System.NullReferenceException" in
system.windows.forms.dll
|
by: Yoni Rabinovitch |
last post by:
Hi,
I am new to C#, so I apologise if this is a stupid question.
I have some 3rd party C++ code, which gets built as static libraries
(not DLLs).
I want to create a C# form, which will call the C++ code.
So, I understand that I need to create a Managed C++ Wrapper, for any
|
by: gregory_may |
last post by:
This code seems to "work" but I get the following errors:
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
then this one:
An unhandled exception of type 'System.ExecutionEngineException' occurred in
system.windows.forms.dll
Anyone know how to either trap these errors or prevent them from...
|
by: Rafael |
last post by:
Hi, I hope I can find some help for this problem
IDE: Visual Studio.NET 2003 Developer Editio
Language: C#
Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object.
Visual Studio's IDE is not allowing me to...
|
by: sarah |
last post by:
Using .NET C# installed Framework 1.1 with Service Pack 1
I have a MDI application in C# that contains 3 different forms. Form
1 has several controls one of which is a DataGrid control that works
fine. Form 2 has several controls, none of which ia a DatGrid
control. Form 3 has several controls, none of which as a DataGrid. In
this...
| |
by: muralidharan |
last post by:
WebForm1.aspx Code:
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI"
Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView
id="TreeView1" Height="520" AutoPostBackOnNodeMove="false"
DragAndDropEnabled="true"
NodeEditingEnabled="False" KeyboardEnabled="true"
CssClass="TreeView" NodeCssClass="TreeNode"...
|
by: Raed Sawalha |
last post by:
i have a windows form(Main) with listview, when click an item in listview i
open other window form (Sub) which generate the selected item from parent
window in as treeview items when click any item in treeview i display the
content item in axWebBrowser, i close the sub form normally when i close the
main the following error is generated
An...
|
by: Patrick.O.Ige |
last post by:
I'm loading an Array below but getting the error "Object reference not set to
an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"),
TextBox).Text' is the error line.
I DON'T KNOW WHAT I'M DOING WRONG I USED ASP.NETWebMatrix and its working
well!!
Any help!!
I have declared ItemNumber as u can see below
" :-
|
by: William Mild |
last post by:
I must be getting brain fried. I can't see the error.
Create a new web form with the following code begind:
Public Class test
Inherits System.Web.UI.Page
Public Class ReportCardData
Public Structure Attend
Dim DaysTardy As Double
|
by: Alex J. |
last post by:
I just started to learn C# (my background is in C++), and right now I
study the sockets, TCP/IP etc... so, I found a usefull source code at:
http://www.codeguru.com/Csharp/Csharp/cs_network/sockets/article.php/c8781/.
But there is a scenarion that throw a strange exception. So, the client
is connected to the server, I send a message from...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |