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");
}
Related
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.
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.
I have a simple program that loads a DLL from the current path
#include <iostream>
#include <windows.h>
using namespace std;
auto loaddll(const char * library) {
auto dllModule = LoadLibrary(library);
if(dllModule == NULL)
throw "Can't load dll";
return dllModule;
}
int main() {
try {
auto Handle = loaddll("ISab.dll");
} catch(const char * error) {
cerr << "An Unexpected error :" << error << endl;
cerr << "Get Last Error : " << GetLastError();
}
}
the load library fails for every DLL in the current path but succeeds for DLL like User.dll
if I ran it output will be like
An Unexpected error :Can't load dll
Get Last Error : 0
this also fails if i specify full path to dll
When a Win32 API call fails, and sets the error code, you must call GetLastError before calling any other Win32 API function. You don't do that.
Raising an exception, streaming to cerr etc. are all liable to call other Win32 API functions and so reset the error code.
Your code must look like this:
auto dllModule = LoadLibrary(library);
if (dllModule == NULL)
auto err = GetLastError();
Once you have the error code you should be better placed to understand why the module could not be loaded. Common error codes for LoadLibrary include:
ERROR_MOD_NOT_FOUND which means that the module, or one of its dependencies, cannot be located by the DLL search.
ERROR_BAD_EXE_FORMAT which invariably means a 32/64 bit mismatch, either with the module you load, or one of its dependencies.
I am trying to load a bitmap with allegro 5.0.10
ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_set_path_filename(path, "Bitmap.bmp");
al_init_image_addon();
ALLEGRO_BITMAP *bmp = al_load_bitmap(al_path_cstr(path, '/'));
if (!bmp) {
fprintf(stderr, "No Background.bmp in this directory...");
return -2;
}
al_draw_bitmap(bmp, 0, 0, 0);
Once i tried to run the program in debug mode, i get this error:
Assertion failed!
Program: c:\allegro\bin\allegro-5.0.10-monolith-md-debug.dll
File: allegro-git\src\system.c
Line: 336
Expression: active_sysdrv
...
How do i fix this?
You need to initialize allegro by calling al_init(). Very few Allegro functions can be called before doing that.
#junyi00, you need to make sure that you call al_init() before trying to load any resources. In your code above, make sure al_init() is already called before calling al_get_standard_path(ALLEGRO_RESOURCES_PATH), al_set_path_filename(path, "Bitmap.bmp"), al_load_bitmap(al_path_cstr(path, '/')) and basically all the Allegro functions from there. No other Allegro functions can be called before this function except one or two. See http://manpages.ubuntu.com/manpages/artful/en/man3/al_init.3alleg5.html and http://manpages.ubuntu.com/manpages/zesty/en/man3/al_install_system.3alleg5.html These are links to the al_init() and al_install_system() Allegro function manual pages
I am going throught Multiple Selection in a File Dialog article of code project,
this code works fine for visual studio 2005 but when i run it on visual studio 2010 it gives me an debug assertion as follow,
Unhandled exception at 0x76f515de in MultiSelect.exe: 0xC0000005:
Access violation reading location 0x00000020.
At the following point,
int ret = CFileDialog::DoModal(); //**Point where assersion occures**
Whole function is like follow(Note:-CFECFileDialog inherited from CFileDialog)
int CFECFileDialog::DoModal()
{
if (Files)
{
delete[] Files;
Files = NULL;
delete[] Folder;
Folder = NULL;
}
int ret = CFileDialog::DoModal(); //**Point where assersion occures**
if (ret == IDCANCEL)
{
DWORD err = CommDlgExtendedError();
if (err == FNERR_BUFFERTOOSMALL/*0x3003*/ && Files)
ret = IDOK;
}
return ret;
}
I also ask question for author of that article but he is not replying.
I downloaded the project from CodeProject and got a crash at CFECFileDialog::OnFileNameChange. Using the VS2010 debugger and the "Go to disassembly" option, i saw that the crash was caused by GetParent returning NULL.
As I have no idea why the CommDlg_OpenSave_* macros were called with a "parent" handle, I just tried calling them with the "this" handle (m_hWnd). Works for me.
Try replacing each instance of "GetParent()->m_hWnd" by "m_hWnd" in CFECFileDialog::OnFileNameChange
EDIT: precision, I did not got the crash you had in DoModal