API: How to use Win32 APIs from a SolidWorks VBA macro which must support SW2012 & SW2013.

Document created by Dan Seaman Employee on Aug 29, 2012Last modified by Dan Seaman Employee on Feb 28, 2014
Version 3Show Document
  • View in full screen mode

SolidWorks 2013 ships with VBA 7.1 instead of VBA 6. As a result you will need to change the way you import any Windows APIs your macro uses.


If you want to avoid maintaining multiple versions of all your macros you are going to need to make use of conditional compiler directives (#If Then, #Else, #End If) to make sure your macro is using the correct types and method signatures.


The attached macro uses the SHBrowseForFolder Win32 API as an example. It shows how to use the conditional compiler directives in different situations covering declaring external methods, creating callback methods and using the correct SolidWorks API to get handles to resources.


The result is a macro that automatically matches itself to the SolidWorks environment it finds itself in, whether that's SolidWorks 2012 or 2013, 32-bit or 64-bit.


See https://forum.solidworks.com/docs/DOC-2141 for more details.


- Subscription Services required for full access.

- Looking for more API Examples?


Copyright © 2012 Dassault Systèmes SolidWorks Corp. All rights reserved.
Do not distribute or reproduce without the written consent of Dassault Systèmes SolidWorks Corp.