Code implementation walk through

I am a VB coder, and I taugh myself that...  I really have had very little exposure to VC++ or any C lang to be honest...  I am trying to implement the following code using the MSFT Visual C++ 2005 Express app that is avialable online and I just don't know enough about C to begin to understand how everything works, or how to actually utilize the code that is provided.  Any assistance would be greatly appreciated.  I have assigned 500 points however if someone is willing to walk me through the coding process (Since I am only using C this one time) I will create another points question for the individual that answers the question.  I just want this to be an EXE to be executed without any interface (If possible)...

Code I want to use...

Here is a slightly modified LOCKWS.CPP from the "Locking a window station" example which emulates C-A-D if you run LOCK.EXE:

// lockws.cpp

#define STRICT
#include <windows.h>
#include <fstream.h>

HINSTANCE   hDll;
CHAR        libName[MAX_PATH];
HDESK       hWinlogon;
HANDLE      hThread=0;
DWORD       dwThreadId;
HWND        hGeneric,hDialog;
PSECURITY_DESCRIPTOR psd;

// Log files
//ofstream o("C:\\out");
//ofstream o2("C:\\out2");

DWORD WINAPI threadProc(LPVOID);

//---------------------------------------------------------------------------
//
// Finds Winlogon generic control dialog
//
BOOL CALLBACK findGeneric(HWND hwnd,LPARAM)
{
   CHAR text[1024];
   GetWindowText(hwnd,text,sizeof(text));
   if(!strcmp(text,"Winlogon generic control dialog")) {
      hGeneric=hwnd;
      return FALSE;
   }
   return TRUE;
}
//---------------------------------------------------------------------------
//
// Finds Windows NT security dialog
//
BOOL CALLBACK findDialog(HWND hwnd,LPARAM)
{
   CHAR text[1024];
   GetWindowText(hwnd,text,sizeof(text));
   //o2<<text<<' '<<hwnd<<endl;
   if(!strcmp(text,"Windows NT Security")) {
      hDialog=hwnd;
      return FALSE;
   }
   return TRUE;
}
//---------------------------------------------------------------------------
BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID)
{
   if(fdwReason==DLL_PROCESS_ATTACH) {
      //MessageBeep(-1);
      hDll=hinstDLL;
      GetModuleFileName(hDll,libName,sizeof(libName));

      hWinlogon=OpenDesktop("Winlogon",0,FALSE,
         //DESKTOP_CREATEMENU  |
         //DESKTOP_CREATEWINDOW |
         DESKTOP_ENUMERATE |
         //DESKTOP_HOOKCONTROL |
         //DESKTOP_JOURNALPLAYBACK |
         //DESKTOP_JOURNALRECORD |
         DESKTOP_READOBJECTS
         //DESKTOP_SWITCHDESKTOP |
         //DESKTOP_WRITEOBJECTS
      );
      //o<<"hWinlogon="<<hWinlogon<<endl;

      hThread=CreateThread(0,0,threadProc,0,0,&dwThreadId);
      //o<<"hThread="<<hThread<<endl;

      //if(hThread) {
         // Make sure we are remain after NINJLIB.EXE
         //LoadLibrary(libName);
      //}
   }
   else if(fdwReason==DLL_PROCESS_DETACH) {
      //MessageBeep(-1);
      if(hThread) {
         TerminateThread(hThread,0);
         CloseHandle(hThread);
      }
      CloseDesktop(hWinlogon);
   }

   return TRUE;
}
//---------------------------------------------------------------------------
DWORD WINAPI threadProc(LPVOID)
{
   psd=(PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
      SECURITY_DESCRIPTOR_MIN_LENGTH);
   InitializeSecurityDescriptor(psd,SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(psd,TRUE,0,FALSE);
   SECURITY_ATTRIBUTES sa={
      sizeof(SECURITY_ATTRIBUTES),
      psd,
      FALSE
   };

   HANDLE hEvent=CreateEvent(&sa,FALSE,FALSE,"Nick Lock Station");
   //o2<<"hEvent="<<hEvent<<endl;
   if(hEvent) {
      while(1) {
         //MessageBeep(-1);
         DWORD r=WaitForSingleObject(hEvent,INFINITE);
         if(r==WAIT_OBJECT_0) {
            HWND w=FindWindow("SAS window class","SAS window");
            SendMessage(w,WM_HOTKEY,0,MAKELPARAM(MOD_ALT|MOD_CONTROL,VK_DELETE));
         }
      }
   }
   return 0;
}

-----------------BREAK-------------------

Links I have so far on the topic...

http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_10942141.html
http://www.derkeiler.com/Newsgroups/microsoft.public.platformsdk.security/2004-02/0498.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20903474.html?query=&clearTAFilter=true

Thank you for any help!
LVL 1
gideonnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lakshman_ceCommented:
Create a new project in VS.NET as Windows Console application with name 'Lock'. Paste the following code and compile
// Lock.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
// lockws.cpp

#define STRICT
#include <windows.h>
#include <fstream>

HINSTANCE   hDll;
CHAR        libName[MAX_PATH];
HDESK       hWinlogon;
HANDLE      hThread=0;
DWORD       dwThreadId;
HWND        hGeneric,hDialog;
PSECURITY_DESCRIPTOR psd;

// Log files
//ofstream o("C:\\out");
//ofstream o2("C:\\out2");

DWORD WINAPI threadProc(LPVOID);

//---------------------------------------------------------------------------
//
// Finds Winlogon generic control dialog
//
BOOL CALLBACK findGeneric(HWND hwnd,LPARAM)
{
   CHAR text[1024];
   GetWindowText(hwnd,text,sizeof(text));
   if(!strcmp(text,"Winlogon generic control dialog")) {
      hGeneric=hwnd;
      return FALSE;
   }
   return TRUE;
}
//---------------------------------------------------------------------------
//
// Finds Windows NT security dialog
//
BOOL CALLBACK findDialog(HWND hwnd,LPARAM)
{
   CHAR text[1024];
   GetWindowText(hwnd,text,sizeof(text));
   //o2<<text<<' '<<hwnd<<endl;
   if(!strcmp(text,"Windows NT Security")) {
      hDialog=hwnd;
      return FALSE;
   }
   return TRUE;
}
//---------------------------------------------------------------------------
DWORD WINAPI threadProc(LPVOID)
{
   psd=(PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
      SECURITY_DESCRIPTOR_MIN_LENGTH);
   InitializeSecurityDescriptor(psd,SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(psd,TRUE,0,FALSE);
   SECURITY_ATTRIBUTES sa={
      sizeof(SECURITY_ATTRIBUTES),
      psd,
      FALSE
   };

   HANDLE hEvent=CreateEvent(&sa,FALSE,FALSE,"Nick Lock Station");
   //o2<<"hEvent="<<hEvent<<endl;
   if(hEvent) {
      while(1) {
         //MessageBeep(-1);
         DWORD r=WaitForSingleObject(hEvent,INFINITE);
         if(r==WAIT_OBJECT_0) {
            HWND w=FindWindow("SAS window class","SAS window");
            SendMessage(w,WM_HOTKEY,0,MAKELPARAM(MOD_ALT|MOD_CONTROL,VK_DELETE));
         }
      }
   }
   return 0;
}



int _tmain(int argc, _TCHAR* argv[])
{
      
        hWinlogon=OpenDesktop("Winlogon",0,FALSE,
         //DESKTOP_CREATEMENU  |
         //DESKTOP_CREATEWINDOW |
         DESKTOP_ENUMERATE |
         //DESKTOP_HOOKCONTROL |
         //DESKTOP_JOURNALPLAYBACK |
         //DESKTOP_JOURNALRECORD |
         DESKTOP_READOBJECTS
         //DESKTOP_SWITCHDESKTOP |
         //DESKTOP_WRITEOBJECTS
             );
      //o<<"hWinlogon="<<hWinlogon<<endl;

      hThread=CreateThread(0,0,threadProc,0,0,&dwThreadId);
      //o<<"hThread="<<hThread<<endl;

      //if(hThread) {
         // Make sure we are remain after NINJLIB.EXE
         //LoadLibrary(libName);
      //}

      if(hThread) {
                  TerminateThread(hThread,0);
                  CloseHandle(hThread);
      }
      CloseDesktop(hWinlogon);
   
      return 0;
}

DLLEntryPoint is for DLL. For exe it is main function. Other methods are self explanatory from the code you posted. If you need help understanding let me know.
gideonnAuthor Commented:
This may be a stupid question...  But I went through the process of enabling Win32 on this editor cause I figured it would be better...  Will that change the coding process any, additionally the DLLEntryPoint do I have to tell the editor where to find that or will it know?
gideonnAuthor Commented:
Sorry I am just really out of my element here the syntax structure is significantly different and although I can interrupt what some things do, knowing what they mean and how they work, well that’s a completely different ball game.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

lakshman_ceCommented:
>>additionally the DLLEntryPoint do I have to tell the editor where to find that or will it know

No need for that.

Windows Console application is by default Win32 and entry point is main . You can see the project properties->Configuration manager to find Win32 already set.

You can let me know what you don't understand in this code. Calls like GetWindowText, FindWindow are similar to what is there in VB
gideonnAuthor Commented:
I tried to run the code and here is the Debug report I don't get it.

----- REPORT -----
------ Build started: Project: Lock, Configuration: Debug Win32 ------
Compiling...
stdafx.cpp
Compiling...
Lock.cpp
d:\c++_dev\lock\lock\lock.cpp(32) : error C2664: 'GetWindowTextW' : cannot convert parameter 2 from 'CHAR [1024]' to 'LPWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\c++_dev\lock\lock\lock.cpp(46) : error C2664: 'GetWindowTextW' : cannot convert parameter 2 from 'CHAR [1024]' to 'LPWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\c++_dev\lock\lock\lock.cpp(67) : error C2664: 'CreateEventW' : cannot convert parameter 4 from 'const char [18]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\c++_dev\lock\lock\lock.cpp(74) : error C2664: 'FindWindowW' : cannot convert parameter 1 from 'const char [17]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\c++_dev\lock\lock\lock.cpp(97) : error C2664: 'OpenDesktopW' : cannot convert parameter 1 from 'const char [9]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://d:\C++_Dev\Lock\Lock\Debug\BuildLog.htm"
Lock - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
lakshman_ceCommented:
Did you create Win32 Console project?
gideonnAuthor Commented:
Yes
lakshman_ceCommented:
I coudl compile it fine in VS.NET 2003.

if you define UNICODE, then GetWindowText will map to GetWindowTextW
same with respect to other functions also.

Go to your project ->properties ->General tab
Set 'Character set' to 'Use Multi-Byte Character Set'
gideonnAuthor Commented:
Sorry for the long delay in response...  Things in the office have been nuts and I haven't had 2 seconds to do side projects, there wasn't a day last week I didn't work over 13 hours...  Anyway I changed the settings as you requested, and you were correct...  "Character Set" was set too 'Use Unicode Character Set', I changed that too 'Use Multi-Byte Character Set' and its still not working.  I am still getting the error that I pasted above including the 'GetWindowTextW' error and all the rest.  If you are willing I will get you another 500 points if you would be willing to download the free app from Microsoft and install it to your VS VC++ 2005 and see what I am seeing.  If not I will give up cause this isn't working I don't get it.  Thanks for your help!
lakshman_ceCommented:
I may not be able to test with VC++ 2005 as it is not installed on my machine. I can possibly help you more to solve this problem. After changing the project setting, Did you do a clean build?

1. if UNICODE is defined, then GetWindowText will map to GetWindowTextW instead of GetWindowTextA.
You can check
#ifdef UNICODE
#undef UNICODE
#endif

(or)

2. Explicitly replace GetWindowText calls with GetWindowTextA

(or)

3. You can use MultiByteToWideChar method to return wide character string and pass it as parameter to GetWindowText
Refer to sample at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/looking_up_a_users_full_name.asp
gideonnAuthor Commented:
Ok I have done option 2, and reconfirmed that the Unicode settings were Multi-Byte and I rebuilt the project when I did that this is the report I recieved.

------ Build started: Project: Lock, Configuration: Release Win32 ------
Compiling...
Lock.cpp
Linking...
Lock.obj : error LNK2001: unresolved external symbol __imp__GetWindowTextA@12
Lock.obj : error LNK2001: unresolved external symbol __imp__InitializeSecurityDescriptor@8
Lock.obj : error LNK2001: unresolved external symbol __imp__SetSecurityDescriptorDacl@16
Lock.obj : error LNK2001: unresolved external symbol __imp__FindWindowA@8
Lock.obj : error LNK2001: unresolved external symbol __imp__SendMessageA@16
Lock.obj : error LNK2001: unresolved external symbol __imp__OpenDesktopA@16
Lock.obj : error LNK2001: unresolved external symbol __imp__CloseDesktop@4
d:\C++_Dev\Lock\Release\Lock.exe : fatal error LNK1120: 7 unresolved externals
Build log was saved at "file://d:\C++_Dev\Lock\Lock\Release\BuildLog.htm"
Lock - 8 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
lakshman_ceCommented:
Can you check if user32.lib and advapi32.lib are in the linker->command line settings.If not add them.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gideonnAuthor Commented:
Ok that worked and I was able to build the application and compile the app...  Unfortunately it isn't working.  =(  All that work for nothing, before I post about question when you compiled the app did you by chance execute it?  Cause when I execute it nothing happens, well I see a console show up and disappear but that’s it.  I truly appreciate your help and dealing with my inexperience!  I really wish I knew more about this language because it is obviously quite powerful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.