Win32 LoadLibrary (error 6) - winapi

My app loads several user plugins while starting using the LoadLibrary function.
_handle = LoadLibrary(fileName);
if (! _handle)
{
printf("GetLastError: %d\n", GetLastError());
return false;
}
return true;
Until now, it works. Since few days, despite the fileName is valid, the LoadLibrary function fails and GetLastError returns 6 (ERROR_INVALID_HANDLE).
This behavior is not systematic. Sometime the LoadLibrary function succeed.
Any ideas on how to debug this and find why my app cannot loads the plugins ?

Related

Cancel downloading symbols in Debug Help Library

Debug Help Library allows to load symbols from external storages. You just call SymSetSearchPath, specifying symbol servers, and then SymLoadModuleExW loads symbols from the specified locations.
Downloading symbols may take some time and I am currently looking for a way to cancel downloading symbols. But suddenly I couldn't find any API for that.
Is there a way to cancel downloading symbols?
You can althrough only at a specific times you have no control over.
To cancel the download you:
Register for the callback funcation with SymRegisterCallback64 or SymRegisterCallbackW64 funcation.
In the callback handle the CBA_DEFERRED_SYMBOL_LOAD_CANCEL message.
e.g.
SymRegisterCallbackW64(process, sym_register_callback_proc64, nullptr);
BOOL CALLBACK sym_register_callback_proc64(__in HANDLE h_process, __in ULONG const action_code, __in_opt ULONG64 const callback_data, __in_opt ULONG64 const user_context)
{
switch (action_code)
{
...
case CBA_DEFERRED_SYMBOL_LOAD_CANCEL:
if(<test for cancel now?>)
{
return TRUE;
}
break;
...
}
// Return false to any ActionCode we don't handle
// or we could generate some undesirable behavior.
return FALSE;
}

How to implement message passing callbacks in an all-in-one (Edge/Firefox/Chrome) browser extension's content script?

Development Environment OS: Windows 7 Enterprise LTS
Browser compatibility minimum requirements: Should support all Edge, Firefox, Chrome browsers, as of 2018.
Current ongoing issue: Unable to run VM on dev workstation; Cannot run Windows 10 VMs to debug Microsoft Edge extensions.
To explain:
An "all-in-one browser extension" refers to a browser extension code that uses the same code with minor differences to work on various WebExtensions / Chrome Extensions supported browsers. At bare minimum, the same codebase should work and run on Edge, Firefox, and Chrome with very minor changes.
Callbacks on the content scripts for Edge/Firefox/Chrome extensions are handled differently.
For unknown reasons, I cannot run VM on my workstation machine. When VM is running, VM client is black. This is a localized issue on my end that I cannot resolve, so I'm forced to find a different solution/alternative.
How are they handled differently on the content scripts:
Edge: browser.runtime.sendMessage uses callbacks, and returns undefined.
Firefox: browser.runtime.sendMessage uses Promises, and returns a Promise.
Chrome: chrome.runtime.sendMessage uses callbacks, and returns undefined.
According to various references:
Firefox / Chrome / MS Edge extensions using chrome.* or browser.*
https://www.smashingmagazine.com/2017/04/browser-extension-edge-chrome-firefox-opera-brave-vivaldi/
On the content scripts, you can declare the following JavaScript snippet at the top in order to create a global variable that can be referenced everywhere else:
//Global "browser" namespace definition.
window.browser = (function() {
return window.msBrowser || window.browser || window.chrome;
})();
Unfortunately, because of the issue I'm experiencing (VM not running), I cannot tell if window.msBrowser is still being used. And this solution is not helpful for me when handling message callbacks when using namespace.runtime.sendMessage.
With all that said, my main question is: How to write a message passing function that can handle callbacks properly?
Currently, I'm using the following code:
function sendGlobalMessage(messageRequest, callback) {
if (chrome && window.openDatabase) {
//This is Chrome browser
chrome.runtime.sendMessage(messageRequest, callback);
}
else if (browser) {
try {
//Edge will error out because of a quirk in Edge IndexedDB implementation.
//See https://gist.github.com/nolanlawson/a841ee23436410f37168
let db = window.indexedDB.open("edge", (Math.pow(2, 30) + 1));
db.onerror = function(e) {
throw new Error("edge is found");
};
db.onsuccess = function(e) {
//This is Firefox browser.
browser.runtime.sendMessage(messageRequest).then(callback);
};
}
catch (e) {
//This is Edge browser
browser.runtime.sendMessage(messageRequest, callback);
}
}
}
I truly felt this is a hacky solution, because the code is based off of browser platform exclusive quirks in order to separate chrome.runtime.sendMessage and browser.runtime.sendMessage API calls, so as to handle callbacks in their respective platforms. I really wanted to change this.
So I'm asking what better ways are there, out there, that is useful to detect the different platforms, and handle message passing callbacks properly at the same time?
Thanks in advance.
I believed I solved it.
EDIT: The FINAL final version (updated and more stable, less message passing):
//Global "browser" namespace definition, defined as "namespace". Can be renamed to anything else.
window.namespace = (function() {
return window.browser || window.chrome;
})();
function sendGlobalResponse(message, callback){
if (window.namespace === window.chrome) {
//Chrome
window.namespace.runtime.sendMessage(message, callback);
}
else if (window.namespace === window.browser) {
//Using instanceof to check for object type, and use the returned evaluation as a truthy value.
let supportPromises = false;
try {
supportPromises = window.namespace.runtime.getPlatformInfo() instanceof Promise;
}
catch(e) { }
if (supportPromises){
//Firefox
window.namespace.runtime.sendMessage(message).then(callback);
}
else {
//Edge
window.namespace.runtime.sendMessage(message, callback);
}
}
}
(Original Post):
The final version (Now obsoleted):
//Global "browser" namespace definition.
window.namespace = (function() {
return window.browser || window.chrome;
})();
function sendGlobalResponse(message, callback){
if (window.namespace === window.chrome) {
//Chrome
window.namespace.runtime.sendMessage(message, callback);
}
else if (window.namespace === window.browser) {
let returnValue = window.namespace.runtime.sendMessage({});
if (typeof returnValue === "undefined"){
//Edge
window.namespace.runtime.sendMessage(message, callback);
}
else {
//Firefox
window.namespace.runtime.sendMessage(message).then(callback);
}
}
}
In the second if statement, by checking to see if the return value of a window.browser.runtime.sendMessage is a Promise or undefined, we can detect if the platform is Firefox or Edge.
I think this is the only solution to handle message passing callbacks/message responses on the content scripts.
I really couldn't think of a better solution than this. So I'll be using this from now on.
But if anyone else knows a better way, a way where you don't need to send out 1 extra dummy message for Firefox and Edge per function call, that would be great!
It sucks that anything inside the content script is not persistent, and even if you store information about what platform the code is being run on, you still have to fetch the information from the background script before filtering out which runtime.sendMessage function to call on, so it doesn't really save much time.

Deprecated: Non-static method SmartyPaginate::connect() should not be called statically

I am using SmartyPaginate plugin for SMARTY Template and its throwing 6-7 errors of same type from this very plugin. All error came up when I upgraded to PHP 7. Although I can disable error showing but I would really like to resolve that permanently.
Deprecated: Non-static method SmartyPaginate::getCurrentIndex() should not be called statically in libs\plugins\function.paginate_prev.php on line 58
Codes that are throwing errors.
if (SmartyPaginate::getCurrentIndex($_id) === false) {
$smarty->trigger_error("paginate_prev: total was not set");
return;
}
I resolved all the static errors. I did with following solutions.
Old Code
if (SmartyPaginate::getCurrentIndex($_id) === false) {
$smarty->trigger_error("paginate_prev: total was not set");
return;
}
New Code
if ((new SmartyPaginate)->getCurrentIndex($_id) === false) {
$smarty->trigger_error("paginate_next: total was not set");
return;
}

CoInitializeSecurity error

I have an .exe that loads 1.dll and 1.dll loads 1_1.dll.
In the .exe I create multiple threads, from one of them I call a function that calls upon a 1.dll function that between other things .. calls a function from 1_1.dll that fails in doing this:
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
//m_iStatus = ERROR_COINITIALIZE_EX;
return;
}
// Set general COM security levels.
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);
if( FAILED(hr) )
{
CoUninitialize();
//m_iStatus = ERROR_COINITIALIZE_SEC;
return;
}
It falis on the call to CoInitializeSecurity with this message:
Security must be initialized before any interfaces are marshalled or unmarshalled. It cannot be changed once initialized.
Can anyone expalin me what is happening here, what am I doing wrong and how should I fix this?
CoInitializeSecurity function...
... is called exactly once per process, either explicitly or implicitly
The only case DLL might need to call CoInitializeSecurity is when it is loaded into process, which is known to not initialize COM on its own. An the process is at all basically a thin host for the DLL. That is, almost never.
It is .EXE's task to do CoInitializeSecurity.

Windows Phone 7 await inside foreach C# 5.0 Async

I'm using the C# async CTP to call some remote functions that return me a URI, I have the following code:
public async Task<Uri> GetUriAsync(string service, string endpoint)
{
Uri result = null;
foreach (var service in _serviceProvider)
{
try
{
result = await service .GetAsync(service,endpoint);
if (result != null)
return result;
}
catch (Exception)
{
}
}
return result;
}
Since there is a await inside the foreach, this method should return in the first await, but by debugging I noticed that when the code reachs the await it jumps to "return result"
I've used async ctp before (not on windows phone) and done code similar to this one.
What is wrong in that?
EDIT: This isn't the debugger error/bug, since the remote call is never done (I have a log in there).
There is nothing wrong with that. The debugging experience in the CTP is far from perfect. It's improved, but still not perfect, in the VS 11 CTP.
At runtime, this should produce the results you're expecting (returning the first result that is not null).
The problem was an internal exception at AsyncCtp dll. It seams that the debugger categorizes this exceptions as First Chance exception and decide not to abort the debug session. By doing the code runs normally but without doing the web request (in this case) leaving the developer to think that everything is ok.
Thanks for the help #Reed.

Resources