vc调用vb的dll出错,大侠给看看呀!
每次都是unknown error
in vb:
====
Public Function Doprintxls(Filename As String)
'
' Macro1 Macro
'
Dim Arr() As String
Dim N As Long
Dim K As Long
Dim B As Variant
Dim ws As Object
Dim nSheets As Integer
Dim pre As Boolean
Dim sh As Worksheet
Dim i As Integer
Workbooks.Open Filename '"d:\excel.xlsx" '循环打开Excel文件"
ReDim Arr(1 To ActiveWorkbook.Sheets.Count)
With ActiveWorkbook
For i = 1 To .Sheets.Count
'MsgBox .Sheets(i).Name
Arr(i) = .Sheets(i).Name
Next i
End With
pre = True
Sheets(Arr).PrintOut Preview:=pre
End Function
in vc:
======
#import "d:\printxlsx.dll"
HRESULT ComInit();
#include "stdio.h"
#include <tchar.h>
#include <string>
using namespace printxlsx; //这里是COM组件名称
using namespace std;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
ComInit();
_printmsxlsPtr MyObj;
MyObj.CreateInstance("printxlsx.printmsxls");
BSTR bstr=SysAllocString( BSTR(L"d:\\excel.xlsx"));
try
{
MyObj->Doprintxls( &bstr );
}
catch(_com_error e)
{
const TCHAR* errormsg = e.ErrorMessage();
return FALSE;
}
return 0;
}