Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bm update to master #7

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
node_modules
build
npm-debug.log
test.js
/data/PERSONS.DBF
/debug*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Yuri Dursin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

* Using optional parameters on constructor call
``` js
var con = new ActiveXObject("ADODB.Connection", {
activate: false, // Allow activate existance object instance, false by default
async: true, // Allow asynchronius calls, true by default (not implemented, for future usage)
var con = new ActiveXObject("Object.Name", {
activate: false, // Allow activate existance object instance (through CoGetObject), false by default
getobject: false, // Allow using name of the file in the ROT (through GetAccessibleObject), false by default
type: true // Allow using type information, true by default
});
```
Expand Down Expand Up @@ -271,7 +271,7 @@ This is a key drawback of v8 engine compared to MS. Consider an example:
if( a.Prop )
{
// If 'Prop' is a dynamic property (i.e. it is not defined in TypeInfo and
// not marked explicitly as a property, then never got here. Even if a.Prop is null or false.
// not marked explicitly as a property, then execution never gets here. Even if a.Prop is null or false.
}
```

Expand Down Expand Up @@ -303,4 +303,6 @@ mocha --expose-gc test

* [durs](https://github.com/durs)
* [somanuell](https://github.com/somanuell)
* [Daniel-Userlane](https://github.com/Daniel-Userlane)
* [alexeygrinevich](https://github.com/alexeygrinevich)

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "winax",
"version": "3.3.4",
"version": "3.4.2",
"description": "Windows COM bindings",
"homepage": "https://github.com/durs/node-activex",
"keywords": [
Expand Down Expand Up @@ -29,6 +29,8 @@
},
"contributors": [
"Yuri Dursin <[email protected]>",
"Somanuell",
"Daniel-Userlane",
"Alexey Grinevich <[email protected]>"
],
"repository": {
Expand Down
61 changes: 37 additions & 24 deletions src/disp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,27 @@ bool DispObject::get(LPOLESTR tag, LONG index, const PropertyCallbackInfo<Value>
else {
if (disp_info->is_property()) opt |= option_property;
is_property_simple = disp_info->is_property_simple();

if (disp->bManaged && tag && *tag && wcscmp(tag, L"ToString")==0)
{
// .NET ToString is reported as a property while we normally use it via .ToString() - i.e. as a method.
is_property_simple = false;
}

}
}
else {
// We were unable to figure out if it is a property or method.
// This is typical for .NET objects. So we may check if it is actually
// a .NET object by checking presense of IReflect interface and then asking
CComPtr<IDispatch> preflect;
HRESULT hr = disp->ptr->QueryInterface(IID_IReflect, (void**)&preflect);
else if ( disp->bManaged && tag && *tag && wcscmp(tag, L"length") == 0) {
DISPID lenprop;

if (SUCCEEDED(hr) && this_prop && SUCCEEDED(disp->FindProperty(L"length", &lenprop)) )
if ( SUCCEEDED(disp->FindProperty(L"length", &lenprop)) )
{

// If we have 'IReflect' and '.length' - assume it is .NET JS Array or JS Object
is_property_simple = true;
}

}
else if (disp->bManaged && tag && *tag && index>=0 ) {
// jsarray[x]
is_property_simple = true;
}
}

Expand Down Expand Up @@ -461,6 +465,7 @@ void DispObject::NodeCreate(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
Local<Context> ctx = isolate->GetCurrentContext();
bool isGetObject = false;
bool isGetAccessibleObject = false;
int argcnt = args.Length();
if (argcnt < 1) {
isolate->ThrowException(InvalidArgumentsError(isolate));
Expand All @@ -485,6 +490,9 @@ void DispObject::NodeCreate(const FunctionCallbackInfo<Value> &args) {
if (opt->Get(ctx, v8str(isolate, "getobject")).ToLocal(&val)) {
if (v8val2bool(isolate, val, false)) isGetObject = true;
}
if (opt->Get(ctx, v8str(isolate, "getaccessibleobject")).ToLocal(&val)) {
if (v8val2bool(isolate, val, false)) isGetAccessibleObject = true;
}
}
}

Expand Down Expand Up @@ -520,24 +528,28 @@ void DispObject::NodeCreate(const FunctionCallbackInfo<Value> &args) {
else {
name.assign((LPOLESTR)*vname, vname.length());

CComPtr<IUnknown> unk;
if (isGetObject)
{
CComPtr<IUnknown> unk;
hrcode = CoGetObject(name.c_str(), NULL, IID_IUnknown, (void**)&unk);
if SUCCEEDED(hrcode) hrcode = unk->QueryInterface(&disp);

} else {
CLSID clsid;
hrcode = CLSIDFromProgID(name.c_str(), &clsid);
if SUCCEEDED(hrcode) {
if ((options & option_activate) == 0) hrcode = E_FAIL;
else {
CComPtr<IUnknown> unk;
hrcode = GetActiveObject(clsid, NULL, &unk);
if SUCCEEDED(hrcode) hrcode = unk->QueryInterface(&disp);
}
if FAILED(hrcode) {
hrcode = disp.CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER);
if (isGetAccessibleObject)
{
hrcode = GetAccessibleObject(name.c_str(), unk);
if SUCCEEDED(hrcode) hrcode = unk->QueryInterface(&disp);
} else {
CLSID clsid;
hrcode = CLSIDFromProgID(name.c_str(), &clsid);
if SUCCEEDED(hrcode) {
if ((options & option_activate) == 0) hrcode = E_FAIL;
else {
hrcode = GetActiveObject(clsid, NULL, &unk);
if SUCCEEDED(hrcode) hrcode = unk->QueryInterface(&disp);
}
if FAILED(hrcode) {
hrcode = disp.CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER);
}
}
}
}
Expand Down Expand Up @@ -1034,7 +1046,8 @@ void VariantObject::NodeValueOf(const FunctionCallbackInfo<Value>& args) {
isolate->ThrowException(DispErrorInvalid(isolate));
return;
}
Local<Value> result = Variant2Value(isolate, self->value, true);
// Last parameter false because valueOf should return primitive value
Local<Value> result = Variant2Value(isolate, self->value, false);
args.GetReturnValue().Set(result);
}

Expand All @@ -1058,7 +1071,7 @@ void VariantObject::NodeGet(Local<Name> name, const PropertyCallbackInfo<Value>&
}

String::Value vname(isolate, name);
LPOLESTR id = (vname.length() > 0) ? (LPOLESTR)*vname : L"valueOf";
LPOLESTR id = (vname.length() > 0) ? (LPOLESTR)*vname : L"valueOf";
if (_wcsicmp(id, L"__value") == 0) {
Local<Value> result = Variant2Value(isolate, self->value);
args.GetReturnValue().Set(result);
Expand Down
27 changes: 23 additions & 4 deletions src/disp.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ bool TypeLibEnumerate(ITypeLib *typelib, int mode, T process) {
return cnt > 0;
}

class DispInfo;

template<typename T>
bool TypeInfoEnumerate(IDispatch *disp, int mode, T process) {
bool TypeInfoEnumerate(DispInfo* dispInfo, int mode, T process) {
IDispatch* disp = dispInfo->ptr;
UINT i, cnt;
CComPtr<ITypeLib> prevtypelib;
if (!disp || FAILED(disp->GetTypeInfoCount(&cnt))) cnt = 0;
Expand All @@ -92,6 +95,21 @@ bool TypeInfoEnumerate(IDispatch *disp, int mode, T process) {
CComPtr<ITypeLib> typelib;
if (info->GetContainingTypeLib(&typelib, &typeindex) == S_OK) {

// Check if typelib is managed
CComPtr<ITypeLib2> typeLib2;

if (SUCCEEDED(typelib->QueryInterface(IID_ITypeLib2, (void**)&typeLib2)) )
{
// {90883F05-3D28-11D2-8F17-00A0C9A6186D}
const GUID GUID_ExportedFromComPlus = { 0x90883F05, 0x3D28, 0x11D2, { 0x8F, 0x17, 0x00, 0xA0, 0xC9, 0xA6, 0x18, 0x6D } };

CComVariant cv;
if (SUCCEEDED(typeLib2->GetCustData(GUID_ExportedFromComPlus, &cv)))
{
dispInfo->bManaged = true;
}
}

// Enumerate all types in library types
// May be very slow! need a special method
/*
Expand All @@ -104,7 +122,7 @@ bool TypeInfoEnumerate(IDispatch *disp, int mode, T process) {
CComPtr<ITypeInfo> tinfo;
if (typelib->GetTypeInfo(typeindex, &tinfo) == S_OK) {
TypeInfoPrepare<T>(tinfo, mode, process);
}
}
}

// Process types
Expand All @@ -121,6 +139,7 @@ class DispInfo {
CComPtr<IDispatch> ptr;
std::wstring name;
int options;
bool bManaged;

struct type_t {
DISPID dispid;
Expand All @@ -137,7 +156,7 @@ class DispInfo {
types_by_dispid_t types_by_dispid;

inline DispInfo(IDispatch *disp, const std::wstring &nm, int opt, std::shared_ptr<DispInfo> *parnt = nullptr)
: ptr(disp), options(opt), name(nm)
: ptr(disp), options(opt), name(nm), bManaged(false)
{
if (parnt) parent = *parnt;
if ((options & option_type) != 0)
Expand All @@ -160,7 +179,7 @@ class DispInfo {

template<typename T>
bool Enumerate(int mode, T process) {
return TypeInfoEnumerate((IDispatch*)ptr, mode, process);
return TypeInfoEnumerate(this, mode, process);
}

inline bool GetTypeInfo(const DISPID dispid, type_ptr &info) {
Expand Down
2 changes: 2 additions & 0 deletions src/stdafx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#define NOMINMAX // To remove conflicts with recent v8 code std::numeric_limits<int>::max()

#include <SDKDDKVer.h>

// Windows Header Files:
Expand Down
Loading