|
I have taken this From News Group, this Post is Quoted by Mr J NewCommer
"for(int i = 0; i < 128; i++) // 128 is semi-random choice
{ /* test it */
CString com;
com.Format(_T("\\\\.\\COM%d"), i);
HANDLE h = CreateFile(com, ...stuff here..., OPEN_EXISTING, ...);
if(h != NULL)
{ /* file exists */
int n = c_Ports.AddString(s);
c_Ports.SetItemData(n, PortExists);
} /* file exists */
else
{ /* open failed */
DWORD err = ::GetLastError();
if(error == ERROR_ACCESS_DENIED)
{ /* in use */
int n = c_Ports.AddString(s);
c_Ports.SetItemData(n, PortInUse);
} /* in use */
else
{ /* no such port */
continue;
} /* no such port */
} /* test it */
where PortExists and PortInUse are some sort of #define or enum values you defined.
I used an owner-draw combo box. PortInUse elements displayed in gray, PortExists in black.
Whenever I dropped the list down, I quickly iterated through all the elements and for
every one of I re-examined the ports to see if they were NOW available (CBN_DROPDOWN
handler did this), and changed the ItemData to indicate what their status was. When I used
a checkbox-style control, I grayed the in-use ports out (the user could set up listeners
on several ports in that program). It allowed for dynamic changes, and it indicated that
the port existed but some other program was using it (I had some special cases for ports I
knew my program was using to avoid confusion). In addition, in this era of USB, you should
handle all WM_DEVICECHANGE messages and re-enumerate the ports (I just added this feature
last year for a client program).
However, someone pointed out that this loop is rather clunky and inefficient, and there is
a better way of enumerating serial ports, which is the references that came up within the
last few months.
"
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
|
can you all please help me in this question??
i am a new user in C++!!
1. how to use an array to implement the queue with the random number in the range 1 to 10??
2. how to use a circulary linked list to implement the queue with random number in the range 1 to 10??
my email address: khyap_2011@yahoo.com
|
|
|
|
|
If you need help, you're going to need to ask the question more clearly - a clearer description of what you're trying to do. Also, if this is a school assignment, then I advise you look at the stuff they've taught you for a while. It can't be hard.
Joel Holdsworth
Wanna give me a job this summer?
Check out my online CV and project history[^]
|
|
|
|
|
|
Seems to be
Don't try it, just do it!
|
|
|
|
|
khyap wrote:
1. how to use an array to implement the queue with the random number in the range 1 to 10??
This one is comprised of three separate items: an array, a queue, and a pseudo-random number. Do you know how to implement each?
khyap wrote:
2. how to use a circulary linked list to implement the queue with random number in the range 1 to 10??
Do you know how to implement a circularly-linked list?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
After many years, I've started developing C++ app to log into another server and perform some tasks. I'm getting the error 1314 (A required privilege is not held by the client), when I execute LogonUser function. Before I'm getting error 1300 (Not all privileges referenced are assigned to the caller), when I execute AdjustTokenPrivileges. I'm thinking that this error 1300 is triggering the error 1314. How can I get rid of these errors? FYI, I'm trying to log into my local machine with the local username/password (LOGIN/PASSWORD). This is a Win 2k pro machine, which is not part of any domain. I'm observing all these error codes while stepping thru the code in MS Visual env.
Last point is, LookupPrivilegeValue is returning an error code of 997 (Overlapped I/O operation is in progress). Could this also be causing the current problem?
Any help or pointer in resolving my current issue is greatly appreciated. Have a nice day & week ahead!
Code snippet:
char *szUserName = (char*)malloc(65);
char *szDomain = (char*)malloc(65);
char *szPassword = (char*)malloc(65);
strcpy(szUserName, "LOGIN");
strcpy(szDomain, ".");
strcpy(szPassword, "PASSWORD");
DWORD dwSize = 50+1;
char szUser[50+1]={0};
PROFILEINFO MyProfile = {0};
LUID Luid;
//The following stmt is throwing error 997 (Overlapped I/O operation is in progress)
if(!LookupPrivilegeValue(NULL, SE_TCB_NAME, &Luid))
{
OutputDebugString("LookupPrivilegeValue failed.\n");
iLastError = GetLastError();
goto Exit;
}
HANDLE hProcToken;
if(!OpenProcessToken(
GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY|TOKEN_DUPLICATE,
&hProcToken))
{
OutputDebugString("OpenProcessToken failed.\n");
iLastError = GetLastError();
goto Exit;
}
TOKEN_PRIVILEGES TokenPriv;
TokenPriv.PrivilegeCount = 1;
TokenPriv.Privileges[0].Luid = Luid;
TokenPriv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
//The following stmt is throwing error 1300 (Not all privileges referenced are assigned to the caller)
if(!AdjustTokenPrivileges(
hProcToken,
FALSE,
&TokenPriv,
0,
NULL,
NULL))
{
OutputDebugString("AdjustTokenPrivileges failed\n");
iLastError = GetLastError();
goto Exit;
}
// Log on as user with valid credentials for accessing the Exchange server.
//The following stmt is throwing error 1314 (A required privilege is not held by the client)
if (!LogonUser(
szUserName,
szDomain,
szPassword,
LOGON32_LOGON_SERVICE,
//LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&hToken))
{
OutputDebugString("LogonUser failed.\n");
iLastError = GetLastError();
goto Exit;
}
Thanx,
harish
|
|
|
|
|
Can anybody help me to solve the problem of video broadcasting using Windows Media format SDK 9.0 with VC++. I am a PG student doing my final semester project on video broadcasting. What I could do is capture the video using webcam and converting the capture video in IDirectDrawStreamSample and play(Run) on my screen using IMediaStream and IMMultiMediaStream. I create the sample using IDirectDrawMediaStream interface's method HRESULT CreateSample(
IDirectDrawSurface *pSurface,
const RECT *pRect,
DWORD dwFlags,
IDirectDrawStreamSample **ppSample
);
I get sample data in ppSample but for broadcasting I need them in INSSBuffer interface. Now to write a sample to Net there is one method of IWmWriter named WriteSample(...). The Windows Media Format SDK outlines following procedure for WriteSample()
To pass a sample to the writer, perform the following steps:
->Allocate a buffer and retrieve a pointer to the INSSBuffer interface by calling IWMWriter::AllocateSample.
->Retrieve the address of the buffer created in step 1 by calling INSSBuffer::GetBuffer.
->Copy your sample data to the buffer location, making sure that the sample passed will fit in the allocated buffer. You can use any memory copying function to copy your data. A common choice is memcpy, which is included in the standard C run-time library.
->Update the amount of data used in the buffer to reflect the actual size of the sample by calling INSSBuffer::SetLength.
->Pass the buffer interface to the writer along with the input number and sample time using the IWMWriter::WriteSample method. All audio samples for an input represent the same duration of content, so you can figure the sample time by adding the sample duration to a running total. For video, you need to calculate the time based on the frame rate.
->WriteSample works asynchronously and might not finish writing the data from the buffer before your application is ready to call the method again. Therefore, it is important to call AllocateSample once for each call to WriteSample. However, you can release the INSSBuffer interface immediately after calling WriteSample.
When you have finished passing samples, call IWMWriter::EndWriting.
I tried the procedure a lot of time but it does not work. I would note that it gives me no error ( either compile time or run time) and everything goes fine but When I try to access the broadcast picture using Window's Media Player it connects to the server and just keeps buffering and continues buffering forever . As player succeeds to connect to server I think Broadcasting of data happens there but what I can not understand is what it lacks that does not get media player to play it. (Later I would be developing my own client to play it rather than using Media Player). Please Help me I have rarely one month before my submission date arrives.
Any suggestions would greatly be appreciated.
Thanks in advance.
Patel Narendra
|
|
|
|
|
Anyone plz tell me as soon as possible how to overwrite a string in a file using vc++?
|
|
|
|
|
If you are using MFC, try CStdIO Class. It will help.
"Aerodynamically, the bumble bee shouldn't be able to fly, but the
bumble bee doesn't know it so it goes on flying anyway." - Mary Kay Ash
My Articles
|
|
|
|
|
IS the result of an MD5 hash Case Sensitive
i.e. are these two md5's can be of same string
4839ab3fbb97ad803801df29502b814b
4839AB3FBB97AD803801DF29502B814B
thanks
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
|
see this link first : http://www.codeproject.com/audio/twaintest.asp
I used CTwain from there.
I included CTwain with my ActiveX control. When i call selectSource it worked. When i call Acquire , the source's user interface is displayed. But the following condition in ProcessMessage(MSG msg) is not become true when clicking on Close(Cancel or Exit) , Ok (or Scan).
if(GetRC() != TWRC_NOTDSEVENT)
{
AfxMessageBox(_T("In TWRC_NOTDSEVENT in ProcessMessage" )); // it not executed always
TranslateMessage(twEvent);
}
Thus TranslateMessage is not called.
I subclassed my control class from CTwain. and in OnCreate i included the following line.
InitTwain(m_hWnd);
if(!IsValidDriver())
{
AfxMessageBox("Unable to load Twain Driver.");
}
and in PreTranslateMessage (BOOL CImgAnnCtrl::PreTranslateMessage(MSG* pMsg))
i included the following line.
ProcessMessage(*pMsg);
Plese help me. What is the problem.
I followed the same procedure in a stand alone(exe (mfc)) application it worked well.
|
|
|
|
|
How can mouse access windows desktop explorer programmatically
using vc++?I want to implement mouse gesture into windows explorer.
How can i recognize mouse co-ordinate in OS's window .
This is my college project .So please help me.
|
|
|
|
|
Try searching something on implementing Windows Hooks. You will find a lot of material here in CodeProject.
"Aerodynamically, the bumble bee shouldn't be able to fly, but the
bumble bee doesn't know it so it goes on flying anyway." - Mary Kay Ash
My Articles
|
|
|
|
|
Can someone give me the begining function to draw multiple lines using MFC? I am having trouble understanding process, I cannot seem to figure out the correct starting point. I am trying to draw (8) different continuous lines using the (sin and cosine) functions based on user input. I only need a starting poin, not the whole thing. Any help appreciated Thank
|
|
|
|
|
Ok... are you trying to do a plot of a cosine and sin function here? If you are then you first need to calculate a list of points, then plot that list. For example:
CClientDC dc(this);
POINT points[100];
for(int i = 0; i<100; i++)
{
points[i].x = i * 5;
points[i].y = sin(i * 0.06283185) * 100 + 100;
}
dc.Polyline(&points, 100); Do a similar process for different functions, and hey presto - 8 functions.
Joel Holdsworth
Wanna give me a job this summer?
Check out my online CV and project history[^]
|
|
|
|
|
Hi all,
I need to disable directx from my display driver.
I need the API that does it.
Please reply if you know anithing about it.
Thanks
|
|
|
|
|
Hello, Does Any one know how to create a movie file AVI or MPEG from JPEG or BMP file. I need to create an app that can read images from a directory and create a movie file from that? Please.... any help or pointers in the right directions
|
|
|
|
|
This[^] article might help.
Steve
|
|
|
|
|
I have a windows cluster with 2 servers running Windows Server 2003. Initially, my client-server application was crashing so I was fixing bugs with my code. Now, periodically one the two cluster servers will just restart itself (it's like a hard system crash to where the server just reboots).
The only thing I've noticed that looks a bit odd is that the memory that SQL Server 2000 (Enterprise Edition) uses climbs rapidly until it reaches about half the server's physical memory (~1.5 GB). According to the guy that setup the cluster, this is normal. I think that when a cluster server crashes, it is the one that is currently running the SQL Server.
My application uses ADO (VC++ 6.0) to access data in SQL Server (which is cluster aware). I've setup a program to simulate alot of network traffic (which means alot of database access; opening and closing connections the database constantly). When this stress test is run is when I notice SQL Server's memory climb constantly.
The server crash (restart) is random; think it has happened even without the stresss test going.
I'm desparate for any ideas or thoughts on this matter. Anyone ever experience something simular (i.e. a clustered server restarting itself)?
|
|
|
|
|
I have been having trouble with this program lately and could use a little help.
The program deals with drawing a diamond with a width specified by the user. So that, the widest part of the diamond is 13 *'s long. The diamond is supposed to be drawn with *'s. If anyone can add any input, feel free. Thanks.
|
|
|
|
|
int size,x,y,temp;
size=13;<br />
y=1;<br />
x=size/2;
for(i=0;i<=size-1;i+=2)<br />
{<br />
temp=x;<br />
for(j=0;j<=i;j++)<br />
{<br />
draw at x,y<br />
x++; <br />
}<br />
x=temp--;<br />
y++;<br />
}
I haven't tried the code yet.
<italic>Work hard, Work effectively and a bit of luck is the key to success.
|
|
|
|
|