LockWorkStation - Compilation error - identifier not found - winapi

I am writing an application in which I got to lock the computer screen (OS is Windows). My Application is in C++. For this purpose I used the LockWorkStation() API defined on msdn, http://msdn.microsoft.com/en-us/library/aa376875%28VS.85%29.aspx
I have included windows.h as told but still I am getting compilation error:
.\source.cpp(5) : error C3861: 'LockWorkStation': identifier not found
here is a sample code thats giving error.
#include <Windows.h>
int main()
{
LockWorkStation();
return 0;
}
Please tell me what I am missing here :(
I am using MS-Visual studio 2005.
Regards.

That function was not supported until Windows 2000. The header files are versioned to allow you to build for older versions of Windows. You're going to want to tell the compiler which minimum version of Windows you want to support as follows:
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
...
#include <windows.h>
If you open winuser.h, you can see that it is surrounded by #if(_WIN32_WINNT >= 0x0500) ... #endif, meaning that it is not available unless you are targeting Windows 2000 or higher.
See http://msdn.microsoft.com/en-us/library/aa383745(VS.85).aspx for more information on the version macros. There's also the new NTDDI_VERSION define where you can set them all at once.

Related

C++/CX Header file can't find Microsoft namespace

I have a header file with the following code:
Microsoft::WRL:ComPtr<ID3D11Device2> m_device;
inside a class definition. Visual Studio 2013 is saying that Microsoft is not a namespace, if I take the code and cut it out and put it in another class in another file unchanged it works just fine!
Any ideas?
Philip
EDIT: All of a sudden (without me having changed anything) Intelissense now accepts Microsoft::WRL::ComPtry as valid but when I compile it still gives me errors that it does not exists.
You need to
#include <wrl.h>
or
#include <wrl/client.h>
To get Microsoft::WRL::ComPtr in your module.
When you say "Visual Studio 2013 is saying that Microsoft is not a namespace" do you mean you get a compiler error or is just Intellisense? When dealing with headers, Intellisense can get a bit out of sync until you build again. For example:
//Test.h
class A { Microsoft::WRL::ComPtr<T> a; };
//Test.cpp
#include <wrl/client.h>
#include "Test.h"
If you just added the #include <wrl/client.h> to the Test.cpp, Intellisense might not know yet it is in scope for the header. It's perfectly valid C++ already, but a better practice is to include in your headers the ones it needs like:
//Test.h
#pragma once
#include <wrl/client.h>
class A { Microsoft::WRL::ComPtr<T> a; };
The other way this sync issue can manifest itself is if you are doing:
//Test.h
class A { Microsoft::WRL::ComPtr<T> a; };
//Test.cpp
#include "pch.h"
#include "Test.h"
//pch.h
#include <wrl/client.h>
Again, fully valid C++ that will build. Intellisense knows it works when you build, but might not until then.
Note: WRL is traditional C++ and is not using C++/CX language extensions. They both exist to make it easier to consume WinRT APIs from C++, and you will see the Microsoft::WRL::ComPtr used inside C++/CX applications when dealing with non-WinRT COM APIs like Direct3D. And you can mix C++/CX with WRL in the same application taking advantage of the fact that you can use reinterpret_cast<> between C++/CX ref ^ and ABI COM pointers. You can use Microsoft::WRL::ComPtr in old-school Windows desktop apps on Windows 7 or Windows Vista too.
With all that said, WRL and C++/CX are two distinct things.
Update: For consuming Windows Runtime APIs, you can also use C++/WinRT which is also 'standard' C++ without any need for the C++/CX extensions. See Microsoft Docs. You can use Microsoft::WRL::ComPtr for C++/WinRT applications, or you can use their variant wrl::com_ptr

CUDA __syncthreads() compiles fine but is underlined with red

I have been working with CUDA 4.2 for a week now and I have a little problem.
When I write the __syncthreads() function it becomes underlined and looks like it is wrong...
Then if I put the mouse on the function it appears a message writing:
identifier __syncthreads(); is undefined.
but when i compile my project the output form build says:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
So I am guessing that everything works fine but the fact that Visual Studio underlines the function is confusing me...How can I make Visual studio to know that this function is defined before the compiling process?
NOTE:The same thing happens with the kernel call: kernel<<<...,...>>> where the third "<" is underlined red too...
I know that this probably is a minor problem but i want to solve it...Thanks a lot!
I am using Visual Studio 2010 on win7 with Cuda 4.2 and Nsight 2.2
I added the following few lines to the top of the cu file and it began to recognize these functions. For some reason, Intellisense did not pick up this #define:
#ifndef __CUDACC__
#define __CUDACC__
#endif
I lost some color-coding in the code, but I no longer get strange false positive errors.
I am using CUDA 9.1 and Visual Studio 2017 15.6.4. The following code helps me eliminate the "__syncthreads() is undefined" error.
//for __syncthreads()
#ifndef __CUDACC__
#define __CUDACC__
#endif
#include <device_functions.h>
However, this method is not recommended because it may bring unpredictable side effects. Another method to solve this intellisense warning is:
#ifdef __INTELLISENSE___
// in here put whatever is your favorite flavor of intellisense workarounds
#endif
Reference:
__syncthreads(); is undefined need a help
I have CUDA 8.0 and Visual Studio 2015 and I had the same issue.
The below lines helped me:
After these lines: (already in code)
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
I added these lines:
//for __syncthreads()
#ifndef __CUDACC_RTC__
#define __CUDACC_RTC__
#endif // !(__CUDACC_RTC__)
#include <device_functions.h>
It's based on this link: https://devtalk.nvidia.com/default/topic/1009723/__syncthreads-and-atomicadd-are-undefined-in-visual-studio-2015/
Experienced this when trying to define the body of __global__ functions in .cuh files. Moving the body of the functions into .cu source-file solved it.
However, it means that some of my templated functions can't use essential things like __syncthreads(), because templates might have to be defined in a .cuh header.
So, you might need to abandon function templates and instead stick to several functions, each with a slightly different name.
The other solutions either did not solve the same issue occurring in Eclipse 2021-06 with CMake 3.16.3, or produced the following warning with CUDA Runtime Version = 10.1:
/usr/include/device_functions.h:54:2: warning: #warning "device_functions.h is an internal header file and must not be used directly. This file will be removed in a future CUDA release.
The following gave proper highlighting and code completion in Eclipse, and it didn't produce compile warning:
#ifndef __CUDACC__
#define __CUDACC__
#include <device_functions.h>
#endif

Need help in including lib file in my vc++ project

First of all i am a beginner in visual studio so please forgive and guide me if i m going wrong in some way , i am a java and php programmer so i am not new to programming
i want to develop a application which reads fingerprint , i use this device
http://www.egistec.com/en/sensors/fingerprint-es603wb.aspx
which i think uses Windows Biometric Framework , so i tried to run the code mentioned in this page
http://msdn.microsoft.com/en-us/library/windows/desktop/ee207405(v=vs.85).aspx
this is what i did
#include "stdafx.h"
#include "Windows.h"
#include "Stdio.h"
#include "Conio.h"
#include "Winbio.h"
int _tmain(int argc, _TCHAR* argv[])
{ HRESULT CaptureSample(); }
you can find the function CaptureSample() in the second link provided above.
As you can see in the they said to link Winbio.lib, i know that its a dll in system32 , i did some research and created a Winbio.def file and Winbio.lib file,
Now my problem is i dont know how to link the lib file , i added "Winbio.lib" in properties >>LInker >> Additional Dependencies
it shows me the following error
*error LNK2019: unresolved external symbol _WinBioOpenSession#28*
infact this error appears even if i remove it from Additional Dependencies
please tell me where i am going wrong , should i place the lib file in any specific directory ? should i copy the dll somewhere ? or something else ?
Linker > General > Additional library Directoreis
put the path to the lib
Linker > Input
Put the lib name.
You can find this if you do some googling.
If everything is fine and still does not work, very probable that your lib file is not generated correctly. You can then try use dynamic loading of your dll file.
http://msdn.microsoft.com/en-us/library/ms810279.aspx
First loadLibrary is called to get a handle to your dll, then getProcAddress is called to get the pointer to the function. Cast the pointer into the target function defined in your h file. Then you'll be able to call the function.
I had the same problem. Following steps helped me on VS 2015 Community Edition
Right click on the project > Properties.
Linker > Input > then in the Addition Dependencies put winbio.lib; to front

Including a Windows DDK Header

I am writing a user-space Win32 application. However, as part of this application I need to make some DeviceIo calls to the Windows 1394 stack. The header file which contains the prototypes for these DeviceIo calls is included as part of the Windows DDK at:
C:\WinDDK\7600.16385.1\inc\api\ntdd1394.h
(Although the header claims to be "Kernel mode only" the prototypes are for user-space IOCTLs.) I am wondering what the best way to include this file in my application is.
It would be poor practice to #include it directly (the path depends, among other things, on the DDK version) and in addition there is no real need for the DDK to be installed --- the only dependency my application has on it is for this very header file.
Hence I am wondering what the best course of action is? I was considering including a stripped-down version of it directly in my applications source but really am not sure.
I'd say include either a stripped down version, or if what your using is really small, import copy it directly into the main header for your project.
regardless which path you take, I'd say wrap both in #define guards, incase someone else who tinkers with this inports the correct header and causes trouble. Even better would be something to allow the user to either define the path to the DDK or use your stripped down version:
#define EXP(x) #x
#define STR(x) EXP(x)
#if defined(__WIN32_DDK_PATH)
#include STR(__WIN32_DDK_PATH)
#else
//Stripped DDK stuff...
#endif
tested the above using gcc 3.4.5(old I know, but dev-cpp is all I have where I am), works fine
How are you linking against the actual implementations of these functions? The documentation for the library you are linking against should tell you what to #include.
Also, do you need other people to be able to build this application or is it a one-man job? You could always set up a virtual build machine which has the DDK installed and #include the file that way.
Otherwise, yes, including the function prototypes in your own stripped down header file (with a comment to say why you are doing this!) is probably the way to go.
This works for me (taken from one of the samples in DDK):
#define _WIN1394_C
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <ntdd1394.h>
#undef _WIN1394_C

CLSID_CNetworkListManager undeclared identifer - error

I am developing an application to get the networks available on the system. Trying to run the same on windows vista. (The below code is based on the link : http://msdn.microsoft.com/en-us/library/ms697388(VS.85).aspx)
Below is the Code Snippet:
#include "Netlistmgr.h"
#include "Objbase.h"
INetworkListManager* pNLM = NULL;
IEnumNetworks *pEnumNetworks = NULL;
hr = ::CoCreateInstance(CLSID_CNetworkListManager,
NULL,
CLSCTX_LOCAL_SERVER,
IID_INetworkListManager,
(LPVOID*) &pNLM);
error C2065:
'CLSID_CNetworkListManager' :
undeclared identifier
Kindly help... Have i missed any header files/Library files???
Thanks,
Suren
INetworkListManager comes with Vista and up, you need to make sure that you have #define WINVER=600 defined in your source before #include or in the project settings.
You also need to make sure that you have Platform SDK 6.0 and up, if your working with Visual Studio 2008 then you're already using it.

Resources