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 2930
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 happening?
|
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 develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
|
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 configuration everything compiles and runs fine. When I add a
DataGrid control to Form 3 I get the...
| |
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"
SelectedNodeCssClass="SelectedTreeNode"
HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
|
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 unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
...
|
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 client to server and
viceversa and than I stop the server from the 'x' button from the right-up
corner;...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |