ERROR 2019 Linker Error Visual Studio - c++

Hey I hope someone can tell me know to fix this issue I am having i keep getting an error 2019 from Visual studio for the following file. Now most of the functions have been removed so excuse the empty varriables etc.
Error error LNK2019: unresolved external symbol "void * __cdecl OpenOneDevice(void *,struct _SP_DEVICE_INTERFACE_DATA *,char *)" (?OpenOneDevice##YAPAXPAXPAU_SP_DEVICE_INTERFACE_DATA##PAD#Z) referenced in function _wmain c:\Users\K\documents\visual studio 2010\Projects\test2\test2\test2.obj test2
#include "stdafx.h"
#include <windows.h>
#include <setupapi.h>
SP_DEVICE_INTERFACE_DATA deviceInfoData;
HDEVINFO hwDeviceInfo;
HANDLE hOut;
char *devName;
//
HANDLE OpenOneDevice(IN HDEVINFO hwDeviceInfo,IN PSP_DEVICE_INTERFACE_DATA DeviceInfoData,IN char *devName);
//
HANDLE OpenOneDevice(IN HDEVINFO HardwareDeviceInfo,IN PSP_DEVICE_INTERFACE_DATA DeviceInfoData,IN char *devName) {
PSP_DEVICE_INTERFACE_DETAIL_DATA functionClassDeviceData = NULL;
ULONG predictedLength = 0, requiredLength = 0;
HANDLE hOut = INVALID_HANDLE_VALUE;
SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo, DeviceInfoData, NULL, 0, &requiredLength, NULL);
predictedLength = requiredLength;
functionClassDeviceData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(predictedLength);
if(NULL == functionClassDeviceData) {
return hOut;
}
functionClassDeviceData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo, DeviceInfoData, functionClassDeviceData,
predictedLength, &requiredLength, NULL)) {
free( functionClassDeviceData );
return hOut;
}
//strcpy(devName,functionClassDeviceData->DevicePath) ;
hOut = CreateFile(functionClassDeviceData->DevicePath, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
free(functionClassDeviceData);
return hOut;
}
//
int _tmain(int argc, _TCHAR* argv[])
{
hOut = OpenOneDevice (hwDeviceInfo, &deviceInfoData, devName);
if(hOut != INVALID_HANDLE_VALUE)
{
// error report
}
return 0;
}
Been driving me mad for hours. Any help appreciated.
SOLVED THANKS TO CHRIS :-)
Add #pragma comment (lib, "Setupapi.lib")
Thanks

Related

Error on building C++ code in node-gyp when using PathFileExists and PathQuoteSpaces from Shlwapi

I'm really a noob in C++, but I have C++ code and when I run node-gyp build it throws:
error LNK2001: unresolved external symbol __imp_PathQuoteSpacesA
and
error LNK2001: unresolved external symbol __imp_PathFileExistsA.
My code:
#include <node.h>
#include <Shlwapi.h>
// Full path and name of the API
static char g_szAPI[MAX_PATH] = "";
// Handle on the QuickVision window used to comunicate
static HWND g_hWndQV = NULL;
BOOL StartQV(LPSTR lpszCmdLine)
{
STARTUPINFO siStartInfo;
PROCESS_INFORMATION processInfo;
char szCmd[1024];
DWORD retval = 0;
// First we get the installation path and name from the registry
if (!GetApiFullNameFromRegistry(g_szAPI, sizeof(g_szAPI))) {
return FALSE;
}
// If the path name has spaces, the full path name must be enclosed with quotation marks before calling CreateProcess
PathQuoteSpaces(g_szAPI); //<----throw error LNK2001: unresolved external symbol __imp_PathQuoteSpacesA
return (BOOL)retval;
}
BOOL GetApiFullNameFromRegistry(char* szAPI, DWORD dwBufLen)
{
HKEY hKey=0;
LONG retval= -1;
BOOL Flag = FALSE;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_KEY, 0, KEY_QUERY_VALUE|KEY_WOW64_32KEY, &hKey))
{
retval = RegQueryValueEx(hKey, "MjExec", NULL, NULL, (LPBYTE)szAPI, &dwBufLen);
RegCloseKey(hKey);
}
Flag = ERROR_SUCCESS == retval && dwBufLen != 0;
if (Flag) {
Flag = PathFileExists(szAPI); //<----throw error LNK2001: unresolved external symbol __imp_PathFileExistsA
}
return Flag;
}
When I comment the code that throws an error, the code is built successfully.
It was necessary to add #pragma comment(lib, "Shlwapi.lib") at the top of the script to solve the problem
Result:
#pragma comment(lib, "Shlwapi.lib") // <-- adding this
#include <node.h>
#include <Shlwapi.h>
// Full path and name of the API
static char g_szAPI[MAX_PATH] = "";
// Handle on the QuickVision window used to comunicate
static HWND g_hWndQV = NULL;
BOOL StartQV(LPSTR lpszCmdLine)
{
STARTUPINFO siStartInfo;
PROCESS_INFORMATION processInfo;
char szCmd[1024];
DWORD retval = 0;
// First we get the installation path and name from the registry
if (!GetApiFullNameFromRegistry(g_szAPI, sizeof(g_szAPI))) {
return FALSE;
}
// If the path name has spaces, the full path name must be enclosed with quotation marks before calling CreateProcess
PathQuoteSpaces(g_szAPI); // <-- now it works fine
return (BOOL)retval;
}
BOOL GetApiFullNameFromRegistry(char* szAPI, DWORD dwBufLen)
{
HKEY hKey=0;
LONG retval= -1;
BOOL Flag = FALSE;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_KEY, 0, KEY_QUERY_VALUE|KEY_WOW64_32KEY, &hKey))
{
retval = RegQueryValueEx(hKey, "MjExec", NULL, NULL, (LPBYTE)szAPI, &dwBufLen);
RegCloseKey(hKey);
}
Flag = ERROR_SUCCESS == retval && dwBufLen != 0;
if (Flag) {
Flag = PathFileExists(szAPI); // <-- now it works fine
}
return Flag;
}

error LNK2019: unresolved external symbol Direct Sound

So I'm reading "Beginning Game Programming Third Edition" by Jonathan S. Harbour, and I've gotten to the point where he teaches us how to use Direct Sound. The book uses it's own DirectSound.h and DirectSound.cpp files, which were from a previous release of the DirectX SDK, but when I try to compile I get the "LNK2019: unresolved external symbol" error.
1>DirectSound.obj : error LNK2019: unresolved external symbol
_DXTraceA#20 referenced in function "public: long thiscall CSoundManager::Initialize(struct HWND *,unsigned long)"
(?Initialize#CSoundManager##QAEJPAUHWND__##K#Z)
1>DirectSound.obj : error LNK2019: unresolved external symbol
_DirectSoundCreate8#12 referenced in function "public: long thiscall CSoundManager::Initialize(struct HWND *,unsigned long)"
(?Initialize#CSoundManager##QAEJPAUHWND__##K#Z)
I have not implemented any Direct Sound code in my project as yet, the mere presence of these files causes the project to not compile. Without them, the project compiles and runs perfectly.
#ifndef DSUTIL_H
#define DSUTIL_H
#include <windows.h>
#include <mmsystem.h>
#include <mmreg.h>
#include <dsound.h>
class CSoundManager;
class CSound;
class CStreamingSound;
class CWaveFile;
#define WAVEFILE_READ 1
#define WAVEFILE_WRITE 2
#define DSUtil_StopSound(s) { if(s) s->Stop(); }
#define DSUtil_PlaySound(s) { if(s) s->Play( 0, 0 ); }
#define DSUtil_PlaySoundLooping(s) { if(s) s->Play( 0, DSBPLAY_LOOPING ); }
//-----------------------------------------------------------------------------
// Name: class CSoundManager
// Desc:
//-----------------------------------------------------------------------------
class CSoundManager
{
protected:
LPDIRECTSOUND8 m_pDS;
public:
CSoundManager();
~CSoundManager();
HRESULT Initialize(HWND hWnd, DWORD dwCoopLevel);
inline LPDIRECTSOUND8 GetDirectSound() { return m_pDS; }
HRESULT SetPrimaryBufferFormat( DWORD dwPrimaryChannels, DWORD dwPrimaryFreq, DWORD dwPrimaryBitRate );
HRESULT Create( CSound** ppSound, LPTSTR strWaveFileName, DWORD dwCreationFlags = 0, GUID guid3DAlgorithm = GUID_NULL, DWORD dwNumBuffers = 1 );
};
//-----------------------------------------------------------------------------
// Name: class CSound
// Desc: Encapsulates functionality of a DirectSound buffer.
//-----------------------------------------------------------------------------
class CSound
{
protected:
LPDIRECTSOUNDBUFFER* m_apDSBuffer;
DWORD m_dwDSBufferSize;
CWaveFile* m_pWaveFile;
DWORD m_dwNumBuffers;
DWORD m_dwCreationFlags;
HRESULT RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, BOOL* pbWasRestored );
public:
CSound( LPDIRECTSOUNDBUFFER* apDSBuffer, DWORD dwDSBufferSize, DWORD dwNumBuffers, CWaveFile* pWaveFile, DWORD dwCreationFlags );
virtual ~CSound();
HRESULT FillBufferWithSound( LPDIRECTSOUNDBUFFER pDSB, BOOL bRepeatWavIfBufferLarger );
LPDIRECTSOUNDBUFFER GetFreeBuffer();
HRESULT Play( DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lVolume = 0, LONG lFrequency = -1, LONG lPan = 0 );
HRESULT Stop();
HRESULT Reset();
BOOL IsSoundPlaying();
};
//-----------------------------------------------------------------------------
// Name: class CWaveFile
// Desc: Encapsulates reading or writing sound data to or from a wave file
//-----------------------------------------------------------------------------
class CWaveFile
{
public:
WAVEFORMATEX* m_pwfx; // Pointer to WAVEFORMATEX structure
HMMIO m_hmmio; // MM I/O handle for the WAVE
MMCKINFO m_ck; // Multimedia RIFF chunk
MMCKINFO m_ckRiff; // Use in opening a WAVE file
DWORD m_dwSize; // The size of the wave file
MMIOINFO m_mmioinfoOut;
DWORD m_dwFlags;
BOOL m_bIsReadingFromMemory;
BYTE* m_pbData;
BYTE* m_pbDataCur;
ULONG m_ulDataSize;
CHAR* m_pResourceBuffer;
protected:
HRESULT ReadMMIO();
HRESULT WriteMMIO( WAVEFORMATEX *pwfxDest );
public:
CWaveFile();
~CWaveFile();
HRESULT Open( LPTSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags );
HRESULT Close();
HRESULT Read( BYTE* pBuffer, DWORD dwSizeToRead, DWORD* pdwSizeRead );
HRESULT Write( UINT nSizeToWrite, BYTE* pbData, UINT* pnSizeWrote );
DWORD GetSize();
HRESULT ResetFile();
WAVEFORMATEX* GetFormat() { return m_pwfx; };
};
#endif // DSUTIL_H
///////////////////////////////////////////////////////////////////////////////
// The function that causes the error
HRESULT CSoundManager::Initialize(HWND hWnd, DWORD dwCoopLevel)
{
HRESULT hr;
SAFE_RELEASE(m_pDS);
// Create IDirectSound using the primary sound device
if(FAILED(hr = DirectSoundCreate8(NULL, &m_pDS, NULL)))
return DXTRACE_ERR(TEXT("DirectSoundCreate8"), hr);
// Set DirectSound coop level
if( FAILED( hr = m_pDS->SetCooperativeLevel( hWnd, dwCoopLevel ) ) )
return DXTRACE_ERR( TEXT("SetCooperativeLevel"), hr );
return S_OK;
}
Error LNK2019 is about adding a missing library - a typical problem. You should identify missing symbols, then identify library to additionally link, then add it using #pragma or via project settings.
Also as it's a beginner question, most likely Stack Overflow already has something closely related. Be always sure to run a search for it, compare code snippets to yours.
Application works in visual studio but release/debug exe does not
Which header should I include for DXTrace?
Related questions show that you need dsound.lib and dxerr.lib to be linked in.

Writing binary data to a file in Visual Studio

I have to admit that I am new to C++ and even new to Visual studio. I have to use Visual studio since the rest of the code is in visual studio and want to open a file and then save binary data to it. I have found some help from Visual Studio and found a program which can send strings to a file but I want to send binary data.For this purpose I have amended the program. But the problem is that it is not performing as per expectations and sending some symbols. I know that there are quite a lot of experts on Stack Overflow. Will any body help me in resolving my issue?
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include <strsafe.h>
#include<conio.h>
void DisplayError(LPTSTR lpszFunction);
void __cdecl _tmain(int argc, TCHAR *argv[])
//void __cdecl _tmain()
{
HANDLE hFile;
int DataBuffer[5] = { 1, 2, 3, 4, 5 };
DWORD dwBytesToWrite = 5;
DWORD dwBytesWritten = 0;
BOOL bErrorFlag = FALSE;
printf("\n");
if (argc != 2)
{
printf("Usage Error:\tIncorrect number of arguments\n\n");
_tprintf(TEXT("%s <file_name>\n"), argv[0]);
return;
}
hFile = CreateFile(argv[1], // name of the write
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_NEW, // create new file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
{
DisplayError(TEXT("CreateFile"));
_tprintf(TEXT("Terminal failure: Unable to open file \"%s\" for write.\n"), argv[1]);
return;
}
_tprintf(TEXT("Writing %d bytes to %s.\n"), dwBytesToWrite, argv[1]);
bErrorFlag = WriteFile(
hFile, // open file handle
DataBuffer, // start of data to write
dwBytesToWrite, // number of bytes to write
&dwBytesWritten, // number of bytes that were written
NULL); // no overlapped structure
if (FALSE == bErrorFlag)
{
DisplayError(TEXT("WriteFile"));
printf("Terminal failure: Unable to write to file.\n");
}
else
{
if (dwBytesWritten != dwBytesToWrite)
{
// This is an error because a synchronous write that results in
// success (WriteFile returns TRUE) should write all data as
// requested. This would not necessarily be the case for
// asynchronous writes.
printf("Error: dwBytesWritten != dwBytesToWrite\n");
}
else
{
_tprintf(TEXT("Wrote %d bytes to %s successfully.\n"), dwBytesWritten, argv[1]);
}
}
CloseHandle(hFile);
}
void DisplayError(LPTSTR lpszFunction)
{
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0,
NULL);
lpDisplayBuf =
(LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf)
+ lstrlen((LPCTSTR)lpszFunction)
+ 40) // account for format string
* sizeof(TCHAR));
if (FAILED(StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error code %d as follows:\n%s"),
lpszFunction,
dw,
lpMsgBuf)))
{
printf("FATAL ERROR: Unable to output error code.\n");
}
_tprintf(TEXT("ERROR: %s\n"), (LPCTSTR)lpDisplayBuf);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
}

How to resolve the Winusb linking error?

I've written a WinUSB project for obtaining data from spectrometer, the code seems to work few weeks ago. In the later stage I tried to link this project with CUDA, after few trials I solved the CUDA linker error. Unfortunately I ended up "error LNK2019: unresolved external symbol" in my main program(Winusb project). At first I thought it was because of the .cu files and I decided to remove all the .CU(CUDA)files form the project and still I was keep on getting the same error(LNK2019).
The following is my code for Winusb project (which was working perfectly few weeks back, but now I'm completely lost and needed some help)
Main.cpp
#include "pch.h"
#include <cstdio>
LONG __cdecl _tmain(LONG Argc, LPTSTR * Argv )
{
FILE *output_file1 = fopen("output_file2.txt", "w");
//FILE *output_file2 = fopen("output_file3.txt", "w");
DEVICE_DATA deviceData;
HRESULT hr;
USB_DEVICE_DESCRIPTOR deviceDesc;
BOOL bResult;
BOOL noDevice;
ULONG lengthReceived;
BOOL wrResult = TRUE;
BOOL wr1Result = TRUE;
BOOL RQResult = 0;
UNREFERENCED_PARAMETER(Argc);
UNREFERENCED_PARAMETER(Argv);
//////////////////////Open device ///////////////
hr = OpenDevice(&deviceData, &noDevice);
if (FAILED(hr)) {
if (noDevice) {
printf(_T("Device not connected or driver not installed\n"));
} else {
printf(_T("Failed looking for device, HRESULT 0x%x\n"), hr);
}
std::getchar();
return 0;
}
/////////////////////Get descriptor//////////////////
bResult = WinUsb_GetDescriptor(deviceData.WinusbHandle,
USB_DEVICE_DESCRIPTOR_TYPE,
0,
0,
(PBYTE) &deviceDesc,
sizeof(deviceDesc),
&lengthReceived);
if (FALSE == bResult || lengthReceived != sizeof(deviceDesc)) {
printf(_T("Error among LastError %d or lengthReceived %d\n"),
FALSE == bResult ? GetLastError() : 0,
lengthReceived);
CloseDevice(&deviceData);
return 0;
}
bool sResult = FALSE;bool syResult;
bool sResult1 = FALSE;bool syResult1;
//Initialize
UCHAR Intialize[] = {0x01};
ULONG cbISize = strlen((char*)Intialize);
ULONG InSent = 0;
wrResult = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, Intialize, 1, &InSent, 0);
//Integration time - 700ms
UCHAR Inttime[] = {0x0200100000};
ULONG cbITSize = strlen((char*)Inttime);
ULONG InttimeSent = 0;
wrResult = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, Inttime, 5, &InttimeSent, 0);
//strobe signal
UCHAR strobe1[] = {0x030001};
ULONG strobeSize1 = strlen((char*)strobe1);
ULONG strobeSent1 = 0;
wr1Result = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, strobe1, 3, &strobeSent1, 0);
//Request spectra
UCHAR Rqspectra[] = {0x09};
ULONG RqSize = strlen((char*)Rqspectra);
ULONG RqSent = 0;
RQResult = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, Rqspectra,1, &RqSent, 0);
//Pixel Values
UCHAR szBuffer[15][512];
UCHAR sz1Buffer[1];
UCHAR tBuffer[1];
ULONG tReadx;
ULONG cbReadx[16];
USHORT newbuf[15][512];
short specbu[7860];
for (int i=0;i<16;i++)
{
if (i<4)
{
sResult = WinUsb_ReadPipe(deviceData.WinusbHandle, 0x86, szBuffer[i], 512, &cbReadx[i], 0);
}
else if (i>=4 && i<15)
{
sResult = WinUsb_ReadPipe(deviceData.WinusbHandle, 0x82, szBuffer[i], 512, &cbReadx[i], 0);
}
else if (i = 15)
{
syResult = WinUsb_ReadPipe(deviceData.WinusbHandle, 0x82, sz1Buffer, 1, &cbReadx[i], 0);
}
}
int pon=0;
for (int k=0;k<15;k++)
{
for (int l=0;l<512;l+=2)
{
newbuf[k][l] = (szBuffer[k][(l+1)]<<8|szBuffer[k][l]);
specbu[pon]= (szBuffer[k][(l+1)]<<8|szBuffer[k][l]);
fprintf(output_file1,"%d\t\n",specbu[pon]);
pon++;
}
}
std::getchar();
CloseDevice(&deviceData);
return 0;
}
My Pch.h
#include <Windows.h>
#include <tchar.h>
#include <strsafe.h>
#include <winusb.h>
#include <usb.h>
#include "device.h"
My device.h
#include
//
// Device Interface GUID.
// Used by all WinUsb devices that this application talks to.
// Must match "DeviceInterfaceGUIDs" registry value specified in the INF file.
// 390a138c-f867-4538-8fd4-46063b842d2b
//
DEFINE_GUID(GUID_DEVINTERFACE_USBApplication2,
0x390a138c,0xf867,0x4538,0x8f,0xd4,0x46,0x06,0x3b,0x84,0x2d,0x2b);
typedef struct _DEVICE_DATA {
BOOL HandlesOpen;
WINUSB_INTERFACE_HANDLE WinusbHandle;
HANDLE DeviceHandle;
TCHAR DevicePath[MAX_PATH];
}
DEVICE_DATA, *PDEVICE_DATA;
HRESULT
OpenDevice(
_Out_ PDEVICE_DATA DeviceData,
_Out_opt_ PBOOL FailureDeviceNotFound
);
VOID
CloseDevice(
_Inout_ PDEVICE_DATA DeviceData
);
My build log
1>------ Build started: Project: USB Application2, Configuration: Win7 Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol "long __stdcall OpenDevice(struct _DEVICE_DATA *,int *)" (?OpenDevice##YGJPAU_DEVICE_DATA##PAH#Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "void __stdcall CloseDevice(struct _DEVICE_DATA *)" (?CloseDevice##YGXPAU_DEVICE_DATA###Z) referenced in function _main
1>C:\Users\bel1\Documents\Visual Studio 2012\Projects\USB Application2\Win7Debug\USBApplication2.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
You will need to add source files (.CPP) into your project that are having implementation of following functions:
OpenDevice
CloseDevice
If you are using a third party library, you need to put the relevant .LIB file into Linker Input of project settings.

Reading the running process from OS and displaying it through C++!

This code will read the running process from OS and display it (C++). Specifically, the OS here is Windows XP. The Problem(error) is in (i think) prototype. By the way, it displays following errors.
Error 1 : error LNK2019: unresolved external symbol _EnumProcesses#12 referenced in function _main
Error 2 : error LNK2019: unresolved external symbol _GetModuleBaseNameA#16 referenced in function "void __cdecl DisplayProcessNameAndID(unsigned long)" (?DisplayProcessNameAndID##YAXK#Z)
Error 3 : error LNK2019: unresolved external symbol _EnumProcessModules#16 referenced in function "void __cdecl DisplayProcessNameAndID(unsigned long)" (?DisplayProcessNameAndID##YAXK#Z)
Error 4 : fatal error LNK1120: 3 unresolved externals C:\Documents and Settings\Windows\My Documents\Visual Studio 2008\Projects\a\Debug\a.exe
#include <afxwin.h>
#include <iostream>
#include <string.h>
#include "psapi.h"
unsigned int i;
using namespace std;
void DisplayProcessNameAndID(DWORD processID);
void main()
{
DWORD aProcesses[1024], cbNeeded, cProcesses;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
cProcesses = cbNeeded / sizeof(DWORD);
for ( i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
DisplayProcessNameAndID( aProcesses[i] );
}
};
void DisplayProcessNameAndID( DWORD processID )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
HANDLE hProcess = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ) ;`
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
};
CString str;
str.Format("Text:%s, PID : %u", szProcessName, processID );
AfxMessageBox(str);
CloseHandle( hProcess );
}
No your issue is not with the prototype - the prototypes in windows.h are fine. If you notice your error message start with LNK which means that the linker is giving the error. This means that the linker can't find those functions.
If you look at the documentation for one of the functions that is giving the error, EnumProcessModules at the very bottom in the Library section you'll see that on Windows XP it requires linking to Psapi.lib. Visual C++ doesn't link to that library by default like it does for Kernel32.lib, which is why any functions defined in that library are fine.
You can add the Psapi.lib to the Additional Libraries section of your project, or just add the line:
#pragma comment(lib, "Psapi.lib")
To the top of the file, which will instruct the linker to use Psapi.lib.