|
i am using it like this:
void CAppClass::fun1()
{
for(int i=0; i<port_count;i++)
{
CPort_Class* p_c=new CPort_Class;
p_c->Open()
p_c->Close();
}
}
|
|
|
|
|
This code opens a port and then later on closes it before going on with the next one. I thought you wanted to have multiple ports open at the same time. Could you clearify?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
yes i want to open the multiple port at same time.
|
|
|
|
|
The code fragment you have shown opens and closes the ports one-by-one. You should rethink your strategy i guess. Without knowing more about what exactly you are trying to achieve it is hard to guess on anything, but you could for example try strating a new thread for each port if there aren't too many ports you want to use (of course you would need to implement proper synchronization as needed), or you could have an array for the port class instances, something like this:
CPort_Class *ports = new CPort_Class[portcount]
for (int port = 0; port < portcount; port++) ports[port].Open();
...
...
for (int port = 0; port < portcount; port++) ports[port].Close();
delete []ports; This is a simplified code fragment, you would of course need to do error checks too.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
now i am crate different thread for each port,now how can i do this?
|
|
|
|
|
If you don't know threading then you have a lot to learn. There are great articles about threading all around the web so google away. But if you do not know threading yet then maybe the other solution would be better for you, but as said, since i do not know what you are trying to achieve, it is hard to say.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
|
You are probably specifying it an invalid handle or the instance of which you are trying to use its m_hComm member has been deleted OR it never existed at all and you are calling into some random pointer.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Hi experts, I am reading a source file written in C and there is a declaration syntax which is not familiar to me. The source file is from libmad mp3 decoder. When the file in which the declaration is made has a file extension of .c , the c++ compiler is able to compile successfully. I have changed the source file extension to .cpp but the compiler reports an error. When I looked at the line from where the error was reported, I saw an array declaration which I do not understand very well. This is how the array has been declared.
unsigned char (*main_data)[MAD_BUFFER_MDLEN];
The declaration has been made in a structure called mad_stream. I am not certain about the pointer (*main_data) . The following assignment generates an error:
stream->main_data = malloc(MAD_BUFFER_MDLEN);
and Microsoft Visual Studio 2005 reports the following error:
.\mad\layer3.cpp(2531) : error C2440: '=' : cannot convert from 'void *' to 'unsigned char (*)[2567]'<br />
Could someone please explain to me what is happening? What should I do?. Thanks.
|
|
|
|
|
I think this is an array of unsigned char pointers.
unsigned char (*main_data)[MAD_BUFFER_MDLEN]; is somewhat equivalent to:
unsigned char **main_data;
The difference is that in the first declaration above, the entire array is created on the stack by the compiler.
You don't need to allocate this array with malloc since it's already on the stack.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Right Richie, but do you have any idea how I should allocate the memory in C++ with the new operator for it to work? I still can't figure it out.
For instance, I was playing with this syntax in both C and C++. As an example, the following code compiled successfully when the file extension was .c :
#include <stdio.h>
int main(void)
{
char (*ptr)[40];
ptr = malloc(40);
free(ptr);
return 0;
}
However, by just changing the source file to .cpp , the code doesn't compile. Anyway of accomplishing this in C++?
modified on Sunday, July 17, 2011 7:14 PM
|
|
|
|
|
Can you say exactly what error it gives when you say it doesn't compile in C++?
I know why it won't compile in C++, it's because C++ has stricter type checking.
You need to cast the output of the malloc call thus:
*ptr = (char*)malloc( sizeof(char*) * 40 );
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: I think this is an array of unsigned char pointers.
Sorry Richard, you are incorrect. This (awful) syntax needs to be read from inside the parenthesis and then right to left so that:
(*main_data) is a pointer, to [MAD_BUFFER_MDLEN] an array this length of unsigned char s.
The best things in life are not things.
|
|
|
|
|
char (*p)[10]; is declaring a pointer to a fixed size array and is different from char *p[10]; which simply means an array of 10 pointers.
You allocate memory using p = new char[2][10]; and deallocate using delete [] p;
|
|
|
|
|
Superman, thanks for stepping in.
What is the difference between a "fixed size array" and an "array of 10 pointers?"
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Excellent. I just learned something very useful.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I thought I understood this but I am now confused as to the memory allocation. Why new char[2][10] and not just new char[10] ? Isn't p just an array of characters?
The best things in life are not things.
|
|
|
|
|
Take a look at the following examples.
Say I have a function as below -
void fun(char (*p)[10])
{
cout << *p << endl;
} Now you will be able to call it as -
char name[10];
strcpy_c(name, "Hello");
fun(&name); But you will get a compile error if you try something like -
char name[11];
strcpy_c(name, "Hello");
fun(&name); You could have a slightly different version using references -
void fun(char (&r)[10])
{
cout << r << endl;
}
char name[10];
strcpy_c(name, "Hello");
fun(name);
char name2[11];
strcpy_c(name2, "Hello");
fun(name2); So even though the code calling the function looks exactly like it does when using a function accepting a simple character pointer, it is a safe function.
This is exactly how the new safe string functions are implemented.
The advantage here is that you do not need to pass in a second size parameter to the function and the check for the size is done by the compiler at compile time.
But when you allocate memory using new , then it becomes something like -
char (*p)[10] = new char[5][10]; You can now pass this on to a function, but you would need another level of indirection -
void fun(char (**p)[10]){}
fun(&p); Or
void fun(char (*&p)[10]){}
fun(p);
|
|
|
|
|
Thanks, it all begins to make sense now.
The best things in life are not things.
|
|
|
|
|
Please advise.
I want to control microphone gain in my application, however, in wave library there in no such thing as waveInSetVolume.
It looks like I need to learn how to use “mixer” API's.
Is “mixer” API the only way to accomplish this in Windows?
Mixer API seems pretty complex and I do not want to waste time on it to find out it is not the best API to use to control audio input gain.
Any constructive suggestions will be as always appreciated.
Cheers
Vaclav
|
|
|
|
|
Yes the mixer APIs are the worst I've ever worked with, especially since Windows Vista.
Since you're using the old wavexxx APIs you may as well use the mixer APIs.
If you were using other APIs/framework, DirectX (DirectSound) has control. On Vista and later there's also WASAPI and Media Foundation.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark,
do the other API's / frameworks use same goofy terminology to define input device and selected output device? I am having a heck of a time understanding "mixer" "line" terminology and the way "ends" of such line are identified.
Seems like lots of unnecessary work.
I have also "discovered " that device ID in wave and in "mixer" are opposite.
I have two (so far) and they are exactly opposite to identify.
I bet one of them was developed on Northern hemisphere and the other on Southern!
|
|
|
|
|
I have made a program under VS 2010. It doesn't work on XP on other machines than mine. It asks on some DLLs.
What can I do to build a program with VS 2010 that is fully compatible with Windows XP?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
You need to find out which DLLs are required and install them on the other machines. Generally this will be the Win32 or MFC redistributable libraries; see here[^] for further details.
The best things in life are not things.
|
|
|
|