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

Code Not Working #1

Closed
TommasoBelluzzo opened this issue Jan 31, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@TommasoBelluzzo
Copy link

commented Jan 31, 2019

Dear jet2jet, thanks for sharing this great piece of code. I'm opening this issue because, unfortunately, I can't get it to work on my system. First of all, there are a few leftovers that prevent the compilation of the VBA project.

  1. The function ParseGUID is not defined. Not really a problem, I just recovered it from your website and I copy-pasted it in the script.
  2. CallGetIDsOfNamesImpl calls an undefined function VBQueryInterfaceByString. I couldn't find the declaration in your website, so I fixed the issue by removing the CallGetIDsOfNamesImpl.
  3. CLRInvokeMethodWithTypes was missing the ByVal MethodName As String argument. I added it manually in the function declaration to solve the issue.
  4. CLRInvokeMethodWithTypes2 was throwing an Invalid ParamArray Use error at ToObject(cmi).Invoke_3(obj, Arguments). For fixing this error, I declared a new variable Dim v() As Variant: v = Arguments and I passed it to the call of Invoke_3.
  5. In the function AddExitHandler there was trailing ^ characters near a pointer variable producing invalid code. They are, in fact, literal declaration of LongPtr type. Removing them fixed the issue, but I’m not sure it’s the correct way to go. Anyway it’s not a required feature.

Once all the fixes were implemented into the code, I was able to successfully compile the VBA project. So I decided to try it out with the example you wrote in the README file, the one that uses the .NET Regex class... but to now avail. The script fails during the initialization of the CLRHost class. Following, a small home-made stack trace:

  • RegexSample => Call host.Initialize(False)
  • Initialize => Set m_host = CreateCorRuntimeHost(Version)
  • CreateCorRuntimeHost => hr = VBCallAbsoluteObject(pMetaHost, 3, vbLong, StrPtr(Version), VarPtr(g(0)), VarPtr(pRuntimeInfo))
  • VBCallAbsoluteObject => hr = DispCallFunc(ObjPtr(Object), CLngPtr(IndexForVftable) * Len(argsPtr(0)), 4, CLng(RetType), c, argVt(lb), argsPtr(lb), VBCallAbsoluteObject)

ERROR: Runtime Error 80020010, Automation Error, Invalid Callee

Following, some additional information concerning my current environment:

  • Windows 10 x64
  • Excel 2016 x32
  • MSCORLIB.dll and MSCOREE.dll 2.4, Framework v4.0.30319, x32 Version

I hope you can really help me out in solving this issue because I would love to use your scripts for a project. Do you think it's possible to make this whole thing work on a 32bit version of Excel?

jet2jet added a commit that referenced this issue Apr 25, 2019

Fix some problems (refs. #1)
* Declare 'ParseGUID'
* Remove unused method 'CallGetIDsOfNamesImpl'
* Add missing argument to 'CLRInvokeMethodWithTypes'
* Fix invalid use of ParamArray variable on 'CLRInvokeMethodWithTypes2'
* Remove '^' suffix for numeric literal (no need to use 64-bit integer here)
@jet2jet

This comment has been minimized.

Copy link
Owner

commented Apr 25, 2019

@TommasoBelluzzo Sorry for late response, and very thanks to your report.

For problems of 1~5, I fixed with 2ecb224.

For about the error 80020010 (DISP_E_BADCALLEE), I cannot reproduce it on Excel, because I only tested the code with 64-bit Excel (and have no 32-bit VBA environment).
But, I found DispCallFunc declaration is invalid (at least prgvt must be ByRef Integer, not ByRef Long). If DispCallFunc is called with (weird) int32 array to prgvt in 32-bit C++ application, the error 80020010 occurs. (not occurs in 64-bit application, interestingly.)
I fixed the definition with 342901b.

Please verify the pushed code whether the problem will not occur.

@TommasoBelluzzo

This comment has been minimized.

Copy link
Author

commented Apr 26, 2019

Now it works! The issue can be closed.

@jet2jet jet2jet closed this Apr 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.