看winmain函数看到这句话的,句柄的意思是标志符,那么应用程序的实例是什么意思?int WINAPI WinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
);
hPrevlnstance:应用程序的先前实例的句柄。对于同一个程序打开两次,出现两个窗口第一次打开的窗口就是先前实例的窗口。对于一个32位程序,该参数总为NULL
为什么那个参数是NULL??
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
);
hPrevlnstance:应用程序的先前实例的句柄。对于同一个程序打开两次,出现两个窗口第一次打开的窗口就是先前实例的窗口。对于一个32位程序,该参数总为NULL
为什么那个参数是NULL??
hPrevlnstance:
hPrevInstance
[in] Handle to the previous instance of the application. This parameter is always NULL. If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first. However, a malicious user can create this mutex before you do and prevent your application from starting. To prevent this situation, create a randomly named mutex and store the name so that it can only be obtained by an authorized user. Alternatively, you can use a file for this purpose. To limit your application to one instance per user, create a locked file in the user's profile directory.
--------------------------------------------------------------------------
前一个应用程序实例的句柄。此参数始终是空的。如果您需要检测到另一个实例是否已存在,创建唯一的已命名的互斥体,使用 CreateMutex 函数。即使互斥体已存在,但该函数将返回 ERROR_ALREADY_EXISTS,CreateMutex 将取得成功。这表示您的应用程序的另一个实例存在,因为它首先创建互斥体。但是,恶意用户可以创建此互斥体,做并阻止应用程序开始之前。若要防止这种情况下,创建随机命名的互斥体和存储,使它仅可以通过授权的用户的名称。或者,您可以为此目的使用的文件。若要限制应用程序,每个用户的一个实例,创建用户的配置文件目录中的锁定的文件。