i got the 100 errors when include a ntddk.h and wdm.h in my program - c++

enter link description here[2][this image shows the error]
I tried this code for block the process before execution.But i got a 100 errors while import a ntddk.h and wdm.h in c++.How to solve it?
Then i got sme erroe like this expected a ')' in my 14 and 22 line of code.
So what should i do for removing the 100 error?
#include <ntstatus.h>
#include<DbgEng.h>
#include<Windows.h>
#include <ntddk.h>
#include <wdm.h>
int main()
{
PEPROCESS process1;
process1 = IoGetCurrentProcess();
HANDLE ProcessId = PsGetCurrentProcessId();
PS_CREATE_NOTIFY_INFO CreateInfo;
PCREATE_PROCESS_NOTIFY_ROUTINE_EX(process1, ProcessId, CreateInfo);
PCUNICODE_STRING ImageFileName;
NTSTATUS CreationStatus;
CreateInfo.CreationStatus = STATUS_ACCESS_DENIED;
ImageFileName = CreateInfo.ImageFileName;
if (ImageFileName == (PCUNICODE_STRING)L"firefox.exe")
{
NTSTATUS result;
result = PsSetCreateProcessNotifyRoutineEx(PCREATE_PROCESS_NOTIFY_ROUTINE_EX(process1, ProcessId, CreateInfo), FALSE);
if (result)
{
printf("blocked");
}
}
return 0;
}
Then i got sme erroe like this expected a ')' in my 14 and 22 line of code.
PCREATE_PROCESS_NOTIFY_ROUTINE_EX(process1, ProcessId, CreateInfo);
result=PsSetCreateProcessNotifyRoutineEx(PCREATE_PROCESS_NOTIFY_ROUTINE_EX(process1, ProcessId, CreateInfo), FALSE);
this is the link for showing my error

Don't mix SDK and DDK headers/libraries in one executable.
If you write a driver, don't include Windows.h. Driver code is not Win32 code.
If you want to create a process in suspended state from another Win32 process, use CREATE_SUSPENDED process creation flag in CreateProcess() (or a similar) Win32 call.
If you want to deny process creation for a particular process from a driver, check this StackOverflow question for the boilerplate code.

Related

netsh.exe error on initializing NDI with custom console

I have an application that works with NDI. But when I initialize it, error occurs: window with title "netsh.exe - Application Error" and error description - "The application was unable to start correctly (0xc0000142). Click OK to close the application". I skip this error and all the required NDI functionality works fine. But this error shouldn't occur anyway. I also found, that this error because of my "custom console" usage - my application is GUI-application and I want to see console window near it in some cases.
Very simplified but problem-contains example of this:
#include <iostream>
#include <Windows.h>
#include "ndi/Processing.NDI.Lib.h"
int main()
{
FreeConsole();
AllocConsole();
SetConsoleActiveScreenBuffer(CreateConsoleScreenBuffer(GENERIC_WRITE | GENERIC_READ, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL));
HMODULE m_NDIHandler = LoadLibraryA("Processing.NDI.Lib.x64.dll");
const NDIlib_v5* (*NDIlib_v5_load)(void) = NULL;
if (m_NDIHandler)
{
*((FARPROC*)&NDIlib_v5_load) = GetProcAddress(m_NDIHandler, "NDIlib_v5_load");
}
const NDIlib_v5* m_NDILib = NDIlib_v5_load();
m_NDILib->initialize();
return 0;
}
(Later I'm using WriteConsole for some purposes). Could you please tell me, what is wrong with my code? Error occur on m_NDILib->initialize();
I updated my NDI to latest version (5.1.3.0) and problem fixed.

CEN XFS: Opening Sensors and Indicator Module Causes Crash

I'm working with trying to get some information from the Sensors and Indicators module, but the program always crashes. When I debug step by step I get the result -48 (WFS_ERR_TIMEOUT) from WFSGetInfo() which means that it has timed out. The Sensor and Indicator registry key is present and the vendor DLL is also present. All the other modules are able to open just fine. Any idea what gives?
The SIU SPI version is 3.02 and I'm using SPI/XFS version 0x0B020003 and XFS SDK 3.20. Would this be one of the issues?
#include "XFS.h"
#include "XFSSIU.h"
int main()
{
XFS xfs = XFS();
xfs.start();
HRESULT hResult = XFSObj.openSession("SIU");
LPWFSRESULT lpResult = NULL;
HRESULT open_result = NULL;
open_result = WFSGetInfo(xfs.getServiceHandle(), WFS_INF_SIU_STATUS, NULL, 120000, &lpResult);
std::cout << open_result << std::endl;
XFSObj.CloseSession();
return 0;
}

LoadLibrary on jvm.dll fails with error code 183

I'm trying to use JNI in C++ to call a method from Java.
I have tried this on a console application and it worked, but when I switch to a DLL that is loaded in any application, it fails with error "ERROR_ALREADY_EXISTS"
HMODULE jvmDLL = LoadLibrary("C:\\Program Files\\Java\\jre1.8.0_191\\bin\\server\\jvm.dll");
if (!jvmDLL) {
int error = GetLastError(); // this returns 183
}
This works perfectly fine on anything but a DLL injected into any application. It shouldn't be null.
Try this instead:
HMODULE jvmDLL = LoadLibrary("C:\\Program Files\\Java\\jre1.8.0_191\\bin\\server\\jvm.dll");
if (!jvmDLL)
jvmDLL = GetModuleHandle("jvm.dll");
}

Success compiling but no display, setting bkcolor

#include <graphics.h>
#include <conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TURBOC3\\");
setbkcolor(CYAN);
getch();
closegraph();
}
The compiling was successful and tried running it, but the result was I see no display for my code It's just a blink of screen and gone back to the console.
you need to point initgraph to bgi subfolder of turboc3
initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
Yes your code may compile successfully but your code is having a runtime problem. Just add these line first below the line you initialized your graphics.
int errorcode = graphresult();
if (errorcode != grOk) { /* an error occurred */
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code(requires process.h) */
}
Through these lines runtime problems of graphics can be detected. Its just a safety method for avoid errors and system crash. Well these lines will tell you that they cannot find the file VGAEGA.bgi file. That's generally the default drivers of graphics.
The reason the file is not found is your path c:\\TURBOC3\\. see this post for avoiding the errors.

Run a command line with c++

I have read several posts about running a command line in c++, but none of them does what I want : no display of the console in an external application when I use the dllfile.
My problem : I want to use a process that picks files from a database. For example : to get a file XYZ.xyz and copy it to the directory MyDirXYZ, I would use the command line
"MyDataGenerator XYZ.xyz C:\MyDirXYZ".
I use Visual studio
Let 's take the following example to clarify the issue, I am trying to create a directory with "mkdir" in C++ , without using CreateDirectory :
First method :
std::string lDirectory("c:\\MyDummyDir")
std::string lCmd("mkdir " + lDirectory);
system((lCmd).c_str());
It will work , however it displays the console when I run it with a dllfile on Excel .
Second Method ( convertToRightFormat() convert a char to a TChar)
std::string lDirectory("c:\\MyDummyDir")
std::string lCmd("mkdir " + lDirectory);
BOOL _status = TRUE;
DWORD _reply, _code;
STARTUPINFO _si = { sizeof(_si) };
PROCESS_INFORMATION _pi;
TCHAR *_cmd = NULL;
_cmd=convertToRightFormat(lCmd.c_str())
_status &= CreateProcess(NULL, _cmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &_si, &_pi);
This method does not work(not even creating the folder) , and obviously it does not work either for the process "MyDataGenerator".
I tried to use the executable MKDIR.EXE and put it in the commandline. In that case, it works , but still does not work for MyDataGenerator.
Is there a generic to make all command lines work, without showing the console?
Thanks you.
#include <Windows.h> // FreeConsole, system
int main(int argc, char* argv[])
{
system("mkdir newdirectoryname");
FreeConsole();
}
This will result in cmd popping up for a split second though. It closes after that.
If thats not acceptable just target the windows subsystem instead of the console one and make sure to not draw the window.