|
Hi All,
I am studying multithreading with Visual Studio 2005.
I have an error with one sample from "Multithreading Applications in Win32 - Jim Beveridge & Robert"
1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)'
/*
SerarhFil.cpp
*/
#include <windows.h>
#include <process.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "MtVerify.h"
DWORD WINAPI SearchProc(void *arg);
#define MAX_THREADS 3
HANDLE hThreadLimitSemaphore;
char szSearchFor[1024];
int main(int argc, char *argv[])
{
WIN32_FIND_DATA* lpFindData;
HANDLE hFindFile;
HANDLE hThread;
DWORD dummy;
int i;
if(argc != 2)
{
printf("Usage: %s <search-string>\n", argv[0]);
return EXIT_FAILURE;
}
strcpy(szSearchFor, argv[1]);
lpFindData = (WIN32_FIND_DATA*) calloc(1, sizeof(WIN32_FIND_DATA));
MTVERFY(hThreadLimitSemaphore = CreateSemaphore(NULL, MAX_THREADS, MAX_THREADS, NULL));
hFindFile = FindFirstFile("*.c", lpFindData);
if(hFindFile == INVALID_HANDLE_VALUE);
return EXIT_FAILURE;
do{
WaitForSingleObject(hThreadLimitSemaphore, INFINITE);
//HERE
MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy));
MTVERFY(CloseHandle(hThread));
lpFindData =(WIN32_FIND_DATA*)calloc(1, sizeof(WIN32_FIND_DATA));
}while(FindNextFile(hFindFile, lpFindData));
FindClose(hFindFile);
for(i=0; i<max_threads;i++)
waitforsingleobject(hthreadlimitsemaphore,="" infinite);
="" mtverfy(closehandle(hthreadlimitsemaphore));
="" return="" exit_success;
}
dword="" _stdcall="" searchproc(void="" *arg)
{
="" win32_find_data="" *lpfinddata="(WIN32_FIND_DATA*)arg;
" char="" buff[1024];
="" file*="" ptrfile;
="" ptrfile="fopen(lpFindData-">cFileName, "r");
if(!ptrFile)
return EXIT_FAILURE;
while(fgets(buff, sizeof(buff), ptrFile))
{
if(strstr(buff,szSearchFor))
printf("%s: %s", lpFindData->cFileName, buff);
}
fclose(ptrFile);
free(lpFindData);
MTVERFY(ReleaseSemaphore(hThreadLimitSemaphore, 1, NULL));
}
Yonggoo
|
|
|
|
|
Yonggoo wrote: 1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)'
Yonggoo wrote: MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy));
Yonggoo wrote: DWORD _stdcall SearchProc(void *arg)
_beginthreadex requires the thread proc that it calls to return an unsigned int . You are passing it a function that returns a DWORD . There is no built in conversion from a DWORD to an unsigned int . Change the return type of the SearchProc to an unsigned int .
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Greetings,
I have a custom class I'm building in an MDI application. How do I use a resource ID (i.e. IDB_CAR1) in my class? I called a method using that resource ID, but my application can't find it even though it is a resource. Is there an "#include" I'm missing somewhere for my custom class? What's really strange, is that when I hover the mouse over the offending variable, it gives me a tooltip stating "define IDB_CAR1 130" so it knows what it is, but when I try to compile it, it tells me that it is an unknown identifier.
Any help would be greatly appreciated.
Thanks,
BP
-- modified at 13:57 Sunday 7th January, 2007
|
|
|
|
|
Did you #include "resource.h" in your cpp file?
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends - you are the man!!!!
Thanks,
BP
|
|
|
|
|
Hi guys
I want to hook the CreateFile function that programs call and record all the file names that an app opens and after call the real CreateFile
pls any help here would be apreciated becose Im in the dark with hooking function othere dll's
|
|
|
|
|
|
How to check the sign bit in 8 bit integer.? is this MSB? thanks.
|
|
|
|
|
ikbahrian wrote: How to check the sign bit in 8 bit integer.? is this MSB?
Yes.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Just use a check like this:
if (var<0)
If the variable in of an unsigned type add a cast to the signed version. For example, assume var is an unsigned int :
if (static_cast<int>(var)<0)
Steve
|
|
|
|
|
Hi all, i am a beginer in the area and i did a small program and i get Link errors, can you tell me what is the problem:
file.h
#include <iostream.h>
class CustBase
{
char * custName;
public:
CustBase(){custName=NULL;}
void Print();
};
file.cpp
#include "CustBase.h"
void CustBase::Print()
{
if(this->custName != NULL)
cout<<this->custName<
|
|
|
|
|
ytubis wrote: Main.obj : error LNK2005: "public: void __thiscall CustBase::Print(void)" (?Print@CustBase@@QAEXXZ) already defined in CustBase.obj
The message above comes because in the code below
ytubis wrote: Main
#include "CustBase.cpp"
void main()
{
CustBase a;
a.Print();
}
you have to include the header file (CustBase.h ) not the source one (CustBase.cpp ).
-----------------------------------------------
ytubis wrote: LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/ZCodeProjectWin.exe : fatal error LNK1120: 1 unresolved externals
This one, I think, states that you have choosen the wrong type of project (you should choose Console Application ).
Hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
How do I keep an application always on top? just like Winamp does.
*
|
|
|
|
|
Call SetWindowPos[^] onto your window, with the hWndInsertAfter parameter set to HWND_TOPMOST .
|
|
|
|
|
It brings the window to the top, but it's not permanent. It goes back when you click on another window. It should be on top all the time. May be like "System modal".
*
|
|
|
|
|
If you would have read the MSDN page I linked to, you'd have noticed this:
HWND_TOP
- Places the window at the top of the Z order.
HWND_TOPMOST
- Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.
|
|
|
|
|
It works! thanks
*
|
|
|
|
|
Hi,
I found a demo software by Microsoft called PlaySound, which shows how to play wave file using DirectX. Everything is cool except it stops playing when the dialog window is deactivated or minimized. I am trying to change it so it would play when window is minimized or deactivated as well.
Would greatly appreciate if someone can help me with this issue.
Thanks,
Alex.
//----------------------------------------------------------------------------
// File: PlaySound.cpp
//
// Desc: The PlaySound sample shows how to load and play a wave file using
// a DirectSound buffer.
//
// Copyright (c) Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
|
|
|
|
|
With the advance from DOS3.3 to Win XP and beyond, One practical issue got lost in the mist.
How do I send an ASCII file to a printer. Admittedly Which Printer?
(Registry Entry somewhere? I can Handle to find the code in the Registry to find an Appropriate entry)
but, essentially, without user intervention or choice, what are the essential steps.
You can see the code I need work every day in the likes of Sainsburry, at the Cash Registers. When one commits a transaction, a Receipt is printed, and the Till Operator was not bothered with questions like on which printer should the receipt be printed, or,formatting questions, etc. This was very simple under DOS. All you did was, create an ASCII file immage with all line lengths, colum allignment etc sorted, and send it to LPT1.
How is it done these days.
On a related topic, How do I 'generically' write code for an additional keypad, like the ones that read a magnetic strip on a charge card (Under DOS accepted as a Text String via stdin)( The latter means that Swiping the card has the same effect as typing it's encoded value on the keyboard), with a keypad to enter a PIN. Such keypad is ofcourse distinct from the standard user qwerty keyboard.
LateNightsInNewry
|
|
|
|
|
Wow. Did you try looking at the articles under "Printing" under the "General C++" section of CodeProject?
led mike
|
|
|
|
|
LateNightsInNewry wrote: With the advance from DOS3.3 to Win XP
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
Some body tell me please how to make my application a program that is automatically start up after windows starting up?
In other word what is the function or source code I have to insert to perform that.
Thanks in advance.
|
|
|
|
|
For an application that runs before a user logs in you can make your app a Windows
service application[^]. These typically have no user interface.
There's also a list of startup programs in the registry for both all users and the current user:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
Mark
|
|
|
|
|
An alternative way is putting a shortcut into the autostart start menu folder.
Don't try it, just do it!
|
|
|
|
|
Put it in the [Start][Programs][Startup] menu Option.
This is by far the safest.
LateNightsInNewry
|
|
|
|