iCAx开思工具箱

标题: 【原创】[原创]测试你的版本号(插件) [打印本页]

作者: 玲玲零零    时间: 2003-5-20 18:33
标题: 【原创】[原创]测试你的版本号(插件)
这是我的第一个VC程序。我只能在这捞点分了,班主加分呀!
  
API中常有一些废除的方法,为了保证你开发的方法能用,也就是说为了保证你开发的平台,常需要测试用户的SW的版本号。
SolidWorks 2003 SP3的版本号是11.3.0。
SolidWorks 2003 SP2的版本号是11.2.0。
SolidWorks 2003 SP1的版本号是11.1.0。
SolidWorks 2003 FCS的版本号是11.0。
SolidWorks 2001Plus SP6的版本号是10.6。
SolidWorks 2001Plus SP5的版本号是10.5。
SolidWorks 2001Plus SP4的版本号是10.4。
SolidWorks 2001Plus SP3的版本号是10.3。
SolidWorks 2001Plus SP2的版本号是10.2。
SolidWorks 2001Plus SP1的版本号是10.1。
SolidWorks 2001Plus FCS的版本号是10.0。
作者: 玲玲零零    时间: 2003-5-20 18:34
附图
作者: 玲玲零零    时间: 2003-5-20 18:40
测试
作者: zzz    时间: 2003-5-20 19:44
怎么没有源代码?
作者: Shadow    时间: 2003-5-20 20:27
不错---是玲玲MM的创作吧~------
作者: darkhorse    时间: 2003-5-20 22:25
请给出源代码。。。
作者: 玲玲零零    时间: 2003-5-21 05:13
// -------------------------------------------------------------------
//
//     Filename: Kkk.cpp
//  Description: This defines the interface to SolidWorks and the
//               initialization routines for the DLL.
//
// -------------------------------------------------------------------
  
// pre-compiled headers
#include "stdafx.h"
  
// MFC includes
#include <afxdllx.h>
  
#include "kkk.h"
#include "SldWorks.h"
#include "ExampleApp.h"
#include <tchar.h>
#include "sldworks_i.c"    // The SolidWorks interface IIDs
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
  
// the application object
CKkkApp* TheApplication = NULL;
CDynLinkLibrary *pDynLinkLibrary = NULL;
  
//The instance of this DLL
HINSTANCE g_hinstDll;
  
// the array that contains the registry information
const char *g_RegTable[][3] = {
//Format is {key, value name, value}
  {"SOFTWARE\\SolidWorks\\Applications\\kkk", 0, "{c750da1f-208e-4331-b7bf-3b18bb79e03a}"},
  {"SOFTWARE\\SolidWorks\\Applications\\kkk\\CLSID", 0, "{c750da1f-208e-4331-b7bf-3b18bb79e03a}"},
  {"CLSID\\{c750da1f-208e-4331-b7bf-3b18bb79e03a}", 0, "kkk"},
  {"CLSID\\{c750da1f-208e-4331-b7bf-3b18bb79e03a}\\InprocServer32", 0, (const char*)-1}, //indicates file path
};
  
static AFX_EXTENSION_MODULE KkkDLL = { NULL, NULL };
  
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
  if (dwReason == DLL_PROCESS_ATTACH)
  {
    //Get an instance of this DLL for Self-Registration
    g_hinstDll = hInstance;
    TRACE0("Kkk.DLL Initializing!\n");
    
    // Extension DLL one-time initialization
    AfxInitExtensionModule(KkkDLL, hInstance);
  
    // Insert this DLL into the resource chain
    new CDynLinkLibrary(KkkDLL);
    pDynLinkLibrary = new CDynLinkLibrary(KkkDLL);
  
  }
  else if (dwReason == DLL_PROCESS_DETACH)
  {
    TRACE0("Kkk.DLL Terminating!\n");
  
    // shut down the sample application
    TheApplication->TerminateApplication();
    delete TheApplication;
  
    // Terminate the library before destructors are called
    delete pDynLinkLibrary;
    AfxTermExtensionModule(KkkDLL);
  }
  return 1;   // ok
}
  
// --------------------------------
//  connections to SolidWorks
// --------------------------------  
  
// this is the function SolidWorks calls to connect
// to the add-in application
  
long InitUserDLL3(LPSLDWORKS pSldWorks)
{
  // this function should be called once per session
  if ( TheApplication != NULL )
  {
    ASSERT ( FALSE );
    return 0;
  }
  
  // start the application
  TheApplication = new CKkkApp(pSldWorks);
  if (!TheApplication->StartApplication())
    return 0;
  
  // connected successfully
  return 1;
}
  
// document callbacks
  
void MenuItemCB(void)
{
   
  BSTR retval;
TheApplication->GetSWApp()->RevisionNumber ( [$retval )]
TheApplication->GetSWApp()->SendMsgToUser ( retval);
  return;
}
  
//Toolbar callbacks
void ToolbarCB0(void)
{
  long retval;
  TheApplication->GetSWApp()->SendMsgToUser2(auT("Button 0 Pressed"), swMbInformation, swMbOk, [$retval)]
  return;
}
  
void ToolbarCB1(void)
{
  long retval;
  TheApplication->GetSWApp()->SendMsgToUser2(auT("Button 1 Pressed"), swMbInformation, swMbOk, [$retval)]
  return;
}
  
void ToolbarCB2(void)
{
  long retval;
  TheApplication->GetSWApp()->SendMsgToUser2(auT("Button 2 Pressed"), swMbInformation, swMbOk, [$retval)]
  return;
}
  
long updateButton(void)
{
  long retval = 1;
  return retval;
}
  
void DllExport SaveAsCB(LPTSTR FileName, LPSLDWORKS pSolidWorks)
{
    return;
}
  
//Register the DLL
  
STDAPI DllRegisterServer(void) {
  HRESULT hr = S_OK;
  //Look up the server's file name
  char szFileName[MAX_PATH];
  GetModuleFileNameA(g_hinstDll, szFileName, MAX_PATH);
  //register entries from table
  int nEntries = sizeof(g_RegTable)/sizeof(*g_RegTable);
  for (int i = 0; SUCCEEDED(hr) [$& i < nEntries] i++) {
    const char *pszKeyName = g_RegTable[0];
    const char *pszValueName = g_RegTable[1];
    const char *pszValue = g_RegTable[2];
    //map rogue value to module file name
    if (pszValue == (const char*)-1)
      pszValue = szFileName;
    HKEY hkey;
  
    //create the key
    long err = ERROR_SUCCESS;
    if (i <= 1) { // the first keys are in HKEY_LOCAL_MACHINE
       err = RegCreateKeyA(HKEY_LOCAL_MACHINE, pszKeyName, [$hkey)]
    } else { //The rest go into HKEY_CLASSES_ROOT
       err = RegCreateKeyA(HKEY_CLASSES_ROOT, pszKeyName, [$hkey)]
    }
  
    if (err == ERROR_SUCCESS) {
      //set the value
      err = RegSetValueExA(hkey, pszValueName, 0, REG_SZ, (const BYTE*)pszValue, (strlen(pszValue)+1));
      RegCloseKey(hkey);
    }
    if (err != ERROR_SUCCESS) {
      //if cannot add key or value, back out and fail
      DllUnregisterServer();
      hr = SELFREG_E_CLASS;
    }
  }
  return hr;
}
  
//Unregister the DLL
STDAPI DllUnregisterServer(void) {
  HRESULT hr = S_OK;
  int nEntries = sizeof(g_RegTable)/sizeof(*g_RegTable);
  for (int i = nEntries - 1; i >= 0; i--) {
  
    const char *pszKeyName = g_RegTable[0];
    long err = ERROR_SUCCESS;
  
    if (i <= 1) { //The last keys are in HKEY_LOCAL_MACHINE
      err = RegDeleteKeyA(HKEY_LOCAL_MACHINE, pszKeyName);
    } else { //Remove the rest from HKEY_CLASSES_ROOT
      err = RegDeleteKeyA(HKEY_CLASSES_ROOT, pszKeyName);
    }
  
    if (err != ERROR_SUCCESS)
      hr = S_FALSE;
  }
  return hr;
}
  
// --------------------------------
//  End of Kkk.cpp
// --------------------------------
作者: darkhorse    时间: 2003-5-21 09:39
::y::y::y
::K::K::K::K
作者: 玲玲零零    时间: 2003-5-21 11:27
谢谢darkhorse加分
作者: client    时间: 2003-5-22 13:29
玲玲零零 wrote:
谢谢darkhorse加分

::y::y::y




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3