The function definition (or should I call it "protoype") was specified in the DirectX SDK, so I can't change it. In C#, the argument reuqired was just an integer. In the C++ implementation, it requires an array of a maximum of 3 elements.
NietzscheDisciple
Posts
-
Problem dealing with a function definition -
Problem dealing with a function definitionHey Anonymous... thanks for the reply! I know that this is a very elementary problem, but I'm new to programming in C++ and learning. I figured out the mistake I was making... I forgot the (System::Int32[]) typecast for MemBuff.
MemBuff = (System::Int32)(StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara));
-
Problem dealing with a function definitionI'm trying to port some code I wrote using DirectSound in C# to Visual C++ (managed). I've got most of it done except for this problem I'm stuck at. I understand that this is a newbie question, so please be gentle The function I'm having a problem with is CaptureBufferObject->Read(arguments) in C++. In C#, the function protoype is:
public Array Read(
int bufferStartingLocation,
Type returnedDataType,
LockFlag flag,
int[] ranks
);My code has the following usage of the Read method.
MemBuffShort = (short[])(StreamCaptureBuffer.Read(StreamCapBuffReadPos, typeof(short), LockFlag.None, 50000));
where MemBuffShort = new short[100000]; In C++, the function prototype is:
public: Array* Read(
int bufferStartingLocation,
Type *returnedDataType,
LockFlag flag,
int ranks __gc[]
);My problem is with the last parameter: int ranks __gc[] I tried the following:
// With the variable declarations
static System::Int32 CapBuffPara[] = new System::Int32[] { 50000 };// Calling the Read method
MemBuff = StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara);However, I get the following error message:
error C2440: '=' : cannot convert from 'System::Array __gc *' to 'int __gc[]'
How do I solve this problem? What needs to be changed? Thanks for your help!
-
Question regarding "typeof" equivalent in VC++ .NETI'm attempting to port a DirectSound application I wrote in VC# (.NET 2003) to VC++ (.NET 2003). I've almost ported the entire code, but I'm stuck on one line, and would really appreciate it if somebody could help me out on this. The line in C# is:
MemBuffer = (short[])(AppCaptureBuffer.Read(StreamCapBuffReadPos, typeof(short), LockFlag.None, 50000));
MemBuffer was previously declared as: private short[] MemBuffer; How would I do this in C++? My problem is with the "typeof" keyword in C#. It signifies the returned data type. C++ doesn't appear to have the "typeof" keyword. How do I write this in C++? Thanks!
-
Streaming AudioCheck out the DirectSound samples in the DirectX SDK. The SDK does not provide an out-of-the-box streaming server solution. However the examples (in native C++ and in C#) give you a good introduction to the handling the audio data. Can't comment about the network aspects.
-
A method to collapse code in the IDEWhile coding in C# in the Visual Studio .NET 2003 IDE, one is able to mark regions using #region and #endregion. Is a similar option available when coding in Visual C++?
-
Inordinate Delaying in Form Display?Hello! I'm attempting to write an application in VC++ .NET 2003. My application works alright, but it takes at least 10 seconds for the Form to be displayed. This happens not just on my work PC (P4 1.5GHz, 768MB RAM) but also on my PC at home (AMD Athlon XP 1700+, 768MB RAM) I've written a similar App in VC# and the Form is displayed almost immediately. In VC++, the Build Time is displayed as 4s. It then takes AT LEAST 10 seconds for the Form to be displayed. My Application is neither large nor complex. I am new to VC++ and my understanding is that all the code is written in the Form.h file, and nothing needs to be added to the Form.cpp file. Is that correct? Do I need to change any Solution properties? They are all currently set at their default values. I would really appreciate any suggestions to improve the speed of Form display. Thanks!
-
Windows Forms App in VC++ .NETI've just started to program Windows Forms apps in VC++ .NET. I have prior experience in developing WinForms apps in C# .NET, and the confusion that leads to my question is rooted in the jump from C# to C++. In C#, when I add a button to the form and create an event handler function this function is visible in my code file. However, in VC++, the designer is the ".h" file and the
InitializeComponent
function is also in the ".h" file. The event handler function is also added in the ".h" file. My question is this: What code is added in the project's ".cpp" file? By that, I mean to ask, what part of my program should be coded in the .cpp file? How do I access the components, saybtn1
,btn2
etc from the .cpp file. -
Question regarding Forms App in VC++ .NETHello All, I'm new to coding in VC++ .NET, but have some experience writing applications in C# .NET. I'm in the process of writing an app for which most of the code is in C++. My question is this: 1. Can I use the Designer in my VC++ project (modifying the file Form1.h) to create the GUI? OR 2. Do I need to follow the method suggested in the following LINK and design the GUI in a C# file and then tie it to the C++ code? Which approach is preferable? Thanks!
-
Control dependent event-firing.I've written a DirectSound application in C# that controls the playback/streaming of audio data. In my application, I have three UserControls. The code for each of these Controls performs a particular DSP task. The following is added in the main form's constructor:
// Tags for DSP Function Radio Buttons
rbDSP1.Tag = new ControlFactory(ctlDSP1.Create);
rbDSP2.Tag = new ControlFactory(ctlDSP2.Create);
rbDSP3.Tag = new ControlFactory(ctlDSP3.Create);On my main form, I have a panel that is used to display these controls. Clicking one of three radio buttons results in the corresponding control being displayed in the panel area. The code for this is as follows:
// On the main form
private void DisplayControl(object sender, System.EventArgs e)
{
RadioButton rb = sender as RadioButton; // cast sender as RadioButton
if (rb != null) // Ensure successful casting
{
if (rb.Checked) // Proceed if checked
{
if (m_DSPControl != null)
{
panelControl.Controls.Remove(m_DSPControl);
m_DSPControl.Dispose();
}
ControlFactory cf = rb.Tag as ControlFactory;
m_DSPControl = cf();if (m_DSPControl != null)
panelControl.Controls.Add(m_DSPControl);
}
}
}// In ctlDSP1 code
public static Control Create()
{
return new ctlDSP1();
}Just as an example, let's say UserControl
ctlDSP1
just has a trackbar that acts as a volume control, and I need to obtain the value of the trackbar to control the volume of the playback buffer (whose code is in the main form). I used Tom's suggestion (http://tinyurl.com/46yov), and it works. However, I still face the following problem: In the main form, how do I ensure that I am creating the Event Handler forctlDSP1
and not for the other controls? -
Accessing an object created by another classTom, could you please clarify which method goes on the main form and which goes in the Control? Thanks!
-
Accessing an object created by another classTom, thanks for the advice. The volume control is just an example. I actually need to perform some DSP functions on the audio data. I have five controls for five DSP functions. I'm trying to first establish communication between these two classes. I'll try what you suggested and see if I can get it to work. Thanks!
-
Accessing an object created by another classChristian, thanks for the reply. In my main form's class, I have an object of the DirectSound
SecondaryBuffer
class. It is declared as follows:public SecondaryBuffer SecBuff = null;
and is initialized later in the code as follows:
SecBuff = new SecondaryBuffer(FileName, ApplicationDevice);
The above code belongs in the class "MainForm" that is declared as
public class MainForm : System.Windows.Forms.Form
Now, I have a separate Control,
public class ctlVolume: System.Windows.Forms.UserControl
All I have in this Control is a trackbar, tbVol. I want the volume of
SecBuff
to change when the trackbar value changes. This is accomplished by calling theVolume
method on this object. How do I access the objectSecBuff
which is in the class MainForm? How do I use interfaces to do it? Thanks! -
Accessing an object created by another classI'm trying to reword the question I asked below in more general terms. From a class
classSecond
how do you check if an objectObj_classFirst
ofclassFirst
has been created? Also, how do you access and modify its value? -
Controls related questionThis is a newbie question, but I would be grateful if someone could clear this concept for me. Suppose I have: 1. A class
cMainForm
that has a DirectSound object,SecBuffer
2. A control for this class,cControl
, that has a trackbar which controls the volume of the DirectSound buffer. How do I get the code in the cControl class to verify and recognize that the object has been created, and how do I use it? My app requires that the code be written in separate classes, because different controls will all access the sameSecBuffer
object. Thanks for your help. -
Timers - Click-number dependent triggeringBrian, thanks for your suggestion. It did, indeed, work very well!
private void Clock_Tick(object sender, EventArgs e)
{
count++;if ((count % 4) == 0) AccentBeatBuffer.Play(0,0); else NormalBeatBuffer.Play(0,0); }
-
Timers - Click-number dependent triggeringI've been working today on a metronome application in C#. I'm using a System.Windows.Forms.Timer variable named "Clock" as my timer. I've implemented basic tempo change functionality by means of a trackbar as follows.
//tbTempo values are in bpm - beats per minute
private void tbTempo_Scroll(object sender, System.EventArgs e)
{
Clock.Interval = 60000/(tbTempo.Value);
}I would now like to implement "accented beats". If a bar has 4 beats, I want the 4th beat to sound different from the preceding 3. Put another way, the first three ticks result in, say,
DrumNormal.wav
being played and the next tick results inDrumAccent.wav
being played. This is repeated till the user presses the "Stop" button. Could I get some tips on how I can implement this? Thanks! -
Stdafx.h and the C1010 and C1034 errorsI'm attempting to write a managed wrapper interface to a native C++ class such that I can access it from within my C# code. I'm using Visual Studio .NET 2003 on Windows 2000. I started a new solution: Visual C++ Projects > Class Library (.NET) My Stdafx.h file has the following in it:
#pragma once
#define WIN32_LEAN_AND_MEAN
// Windows Header Files:
#include
#includeusing std::cout; using std::endl;
In the Solution Explorer, under Source Files I have the following: 1. AssemblyInfo.cpp 2. BiquadCode.cpp (native C++ code) 3. DSPWrap.cpp (the wrapper code) 4. Stdafx.cpp Under Header Files, I have: 1. BiquadCode.h 2. DSPWrap.h 3. resource.h 4. Stdafx.h I've "included" the Stdafx.h file in the first statement of DSPWrap.cpp. On a build attempt, the code generated a C1010 error. For the files BiquadCode.cpp and BiquadCode.h, I've now set the precompiled header option as "Not using precompiled headers". However, this throws a C1034 error \DSPWrap\DSPWrap\Stdafx.h(9): fatal error C1034: windows.h: no include path set My questions are as follows: 1. How do I get this code to compile? 2. Where exactly do I need to "include" the Stdafx.h file? Do I need to do it only once in the wrapper code file? Thanks in advance!
-
A metronome app in C#Thanks for the reply, Christian. I've done some DirectSound programming and it's pretty neat. My apprehension was that the SecondaryBuffer wouldn't clear "cleanly enough" for this application. Esp. if the metronome was going at 180 bpm+.
-
A metronome app in C#I'd like to write a metronome application in C#. What Timer class would you recommend for accurate time-keeping. I also plan on using DirectSound to play the WAV files representing the ticks. Does this impose a significant overhead? If you know of code for a metronome app in C#, I'd appreciate it. This would only be for personal reference. I will not copy the code and use it in my app.