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

"Bad DLL calling convention 49..." on Importing UDFs #735

Closed
johnmatthewswift opened this issue Aug 8, 2017 · 28 comments
Closed

"Bad DLL calling convention 49..." on Importing UDFs #735

johnmatthewswift opened this issue Aug 8, 2017 · 28 comments

Comments

@johnmatthewswift
Copy link

I have the latest release of xlwings, 0.11.4, (obtained from pip) and have added the Excel add-in according to the instructions. I am having problems with the Excel add-in menu from the ribbon, and the latest version of the VBA code for 0.11.4.

I've been able to successfully run Example 6 "udf.zip", but I have to manually run the "ImportPythonUDFs" from the VBA code rather than click the "Import Functions" button from the ribbon. Doing so gives me a "Bad DLL calling convention 49..." error.

The bigger problem is that I cannot start a new project using the commands "xlwings quickstart test" or "xlwings quickstart test --standalone" as when I do I cannot import the User Defined Functions either from the ribbon or by manually running the "ImportPythonUDFs" function from the VBA. Both of these now result in the "Bad DLL calling convention 49" error.

The difference seems to relate to changes in the VBA from the version in the example (0.9.3) which is working ok and the VBA from quickstart in the newest version (0.11.4).

image

@sdementen
Copy link
Contributor

same issue on my side.

@fzumstein
Copy link
Member

If you were using the examples from the homepage, I apologize, they hadn't been updated yet, but that's fixed now.

I assume you have followed the upgrade guide: http://docs.xlwings.org/en/stable/migrate_to_0.11.html

  • Specifically, are you seeing the Version: v0.11.4 in the ribbon and getting a 0.11.4 when doing import xlwings and xlwings.__version__ in a python prompt?

  • Then make sure that the workbook has a reference set to the xlwings addin. The quickstart workbooks should have that automatically, but in some occasions you might still need to uncheck the MISSING... reference and check the xlwings reference.

  • At the same time make sure there is no VBA xlwings module present any more, ie. if you can still run the import functions code manually, that sounds suspicous.

  • Make sure that the dlls next to the python interpreter are the right ones: they were last changed on Feb 19, 2017.

@DougAJ4
Copy link

DougAJ4 commented Aug 9, 2017

I was about to open a new issue, but I will post here. I have a similar problem, but with the differences:

  • I get "MacroOptions method of Application class failed 1004. Make sure you are trusting ...
    The functions are imported successfully and work, in spite of the error message.
    I have imported from a different file (to a different spreadsheet) with no problems

The file raising the error message has 73 functions, of which 56 have the @xw.func header. All 56 are imported, in spite of the message.

Obviously this isn't a big problem for me, but perhaps it might shed some light on the other issues.

@fzumstein
Copy link
Member

This seems to be a different issue though, @DougAJ4: https://stackoverflow.com/questions/11203020/application-macrooptions-and-error-1004 it looks like the function descriptions are too long. Maybe I should remove the "Make sure you are trusting..." again as this is hardcoded and shown no matter what error ocurrs at the moment.

@johnmatthewswift
Copy link
Author

Thanks for writing back so promptly, I now have it working on my machine based on these checks.

What was wrong in my case should it be of use to sdementen or others:
The dll files were outdated in the location of my interpreter in Anaconda. The problem was that I have 2 versions of Python on my machine (Python 3.6 & Anaconda). As Anaconda is set higher in my path I had thought (wrongly) that I could call pip from any command line prompt and it would install to the Anaconda directory. In fact it was updating the package in my Python 3.6 installation. Performing the pip calls from the Anaconda prompt and running through the migration installation guide again has solved the issue,

Sorry for my misunderstanding, there is no issue with xlwings in my case and this can be closed from my perspective. Thanks again for the troubleshooting help.

@DougAJ4
Copy link

DougAJ4 commented Aug 9, 2017

I thought that long function descriptions was going to be the answer for my problem (MacroOptions method of Application class failed 1004), but it turns out it wasn't. By trial and error I found the function causing the problem was:
@xw.func
def C2_PA(a):
m = len(a)
n = m2
c = np.zeros((m,n), dtype = np.float64)
for i in range(0, m):
for j in range(0, m):
c[i,j
2] = a[i][j].real
c[i,j*2+1] = np.float64(a[i][j].imag)
return c.tolist()

Possibly the problem is that the function argument must be any array of python complex numbers, which cannot be passed from Excel. This function is not intended to be called from Excel anyway, so I have just deleted the @xw.func, which removes the error message problem.

@Exceluser
Copy link

I got the same problem as johnmatthewswift, but as Anaconda is the only Python version I got on this pc, I could not resolve the issue using the method he found. Could it be a problem if I do not have administration rights on the pc I am using?

@DeltaW7
Copy link

DeltaW7 commented Aug 17, 2017

Also have this issue, it's a new installation so no old versions, I'm using WinPython-64bit-3.5.3.1Qt5. The setting in excel to trust VBA module is set.

@fzumstein
Copy link
Member

follow the bullet points above. print the xlwings version in the python prompt and make sure it's the same as appears on the addin.

@DeltaW7
Copy link

DeltaW7 commented Aug 17, 2017

sorry missed that.
version in excel = 0.11.4
version from command prompt = 0.10.4

how do I fix this?

@fzumstein
Copy link
Member

upgrade via pip or via the package manager of winpython in your case

@DeltaW7
Copy link

DeltaW7 commented Aug 17, 2017

when I uninstalled via pip it seems to have removed the dll files (got the error saying cannot load dll files)
reinstalling via pip did not work (timed out error

using winpython contol panel did reinstall xlwings (via zip file I downloaded) but the dll is still missing
where can I find the latest dll files ?

@DeltaW7
Copy link

DeltaW7 commented Aug 17, 2017

just a side note when using from command line "python setup.py install"

I get an error :"error: can't copy 'xlwings32.dll': doesn't exist or not a regular file"

@fzumstein
Copy link
Member

I am not familiar with how far the winpython control panel is compatible with setuptools. You can always unzip the xlwings package and manually place the dlls next to python.exe, but I would try pip again as it makes things a lot easier.

@fzumstein
Copy link
Member

I can't replicate your error message on the dlls but you're right, it doesn't place them in the correct place when installed manually. You should really be using pip. You can also download the package and then do pip install path/to/xlwings.tar.gz if you have problems pip installing it directly.

@DeltaW7
Copy link

DeltaW7 commented Aug 18, 2017

got it to work - something went wrong with initial installation, deleted everything and reinstalled

Thank you for your help

@Exceluser
Copy link

Nice!

Mine does now the following: I can import UDFs and they appear in the excel spreadsheet, but when in try to use them, they return a "Bad DLL calling convention" in the desired cell. Any ideas how to make it finally work for me?

@fzumstein
Copy link
Member

fzumstein commented Aug 18, 2017

Bad DLL calling convention still means that your VBA code (addin) is not in sync with the dlls. Just try to make sure everywhere is 0.11.4 installed. Maybe uninstall the python package first, verify that the dlls are gone (delete them manually if not) and then reinstall the correct version. I assume you do see v0.11.4 on the addin.

@Exceluser
Copy link

I do have v.011.4 in the ribbon as well as when i check in the python prompt.

Sorry, if thats a dumb question, but is there a way to uninstall the python package like you mentioned w/o uninstalling the whole anaconda? And which one is the correct version of python i need then?

@boazdori
Copy link

i have been getting the above tried all sugestions still not working working with win10, excel 2016
i have 0.11.4 when checking xw.version on the ribon i see 0.11.4 i ref xlwings.xlam have it as and add in went throught the trust i managed to see helloworld as a macro but no success in importing udfs! what can i check next?

@fzumstein
Copy link
Member

Your 0.11.4 ribbon must be calling the <0.11 dlls. So maybe they were not properly updated when you upgraded xlwings (might happen when they are in use while you update). Try to reinstall xlwings python package. Also make sure you're looking at the right python installation when you have various. I ll be working on proper tools to verify the installation so that we can get rid of these issues in the future.

@boazdori
Copy link

i have uninstalled xlwings and reinstalled again now i am getting the run time error 53 cant fined the 32bit dll i have the xlwings32.dll in the anaconda3 directory same place as the python and pythonw.exe files are located. this happens when trying to run import udf or using import file name in the udf.xlsm file why is the programe not finding the file?

@fzumstein
Copy link
Member

When you do the following in a command prompt, does it point to the directory with the dlls?:

where python

@boazdori
Copy link

yes it does it points to the right directory

@boazdori
Copy link

got it to work by using the python path manager in spyder added the Anaconda3 directory to path and all working
thnkx

@simonm3
Copy link

simonm3 commented Jan 31, 2018

I also have this problem. Not sure if related but I can't see a ribbon either.
Was all working on previous version. Can't get anything to work now.

@DougAJ4
Copy link

DougAJ4 commented Feb 1, 2018

I just updated to 0.11.5 and had a similar problem when first opening an xlwings spreadsheet; UDFs returned "Bad dll calling convention", and the xlwings tab still showed version 0.11.4.

I have my Anaconda Python and associated files (including xlwings) installed on my C: drive, but my data files are installed on D:.. \Documents\Spread\xlwings. Excel indicated that the xlwings.xlam file was installed in the Spread\xlwings folder on the D: drive, but there was no xlam file there; so presumably it was deleted in the update process.

I copied the new xlwings.xlam from c:\Users\douga\Anaconda2\pkgs\xlwings-0.11.5-py27_0\Lib\site-packages\xlwings\addin\ to the Spread\xlwings folder, and re-started Excel, after which the xlwings UDFs worked again.

Note that this is not necessarily the optimal way to do things, but it worked for me.

@fzumstein
Copy link
Member

closing this as too old. feel free to open a new issue if the error persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants