vs2017如何从类型库添加 MFC 类

slowly507 2019-01-09 10:20:26
请教一下,VS2017已经取消了这个功能,那么如果还需要添加该如何操作?
注:我需要添加EXCEL操作的几个类。

...全文
1612 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
q15595882 2021-04-17
  • 打赏
  • 举报
回复
这个问题你解决了吗?可否说一下怎么实现
Duanyuanhao 2020-04-06
  • 打赏
  • 举报
回复
引用 11 楼 cl 的回复:
VS2017打开之后点击项目,之后点击类向导,点击添加类右边的小箭头,选择类型库中的MFC类,进入从类型库添加类向导后,从一下来源添加类,不要选择注册表,选择文件,位置写EXCEL所在的路径,这样可用库就会变成EXCEL的LIB,双击接口添加类即可。
你好,那请问VS2019也可以这样操作吗?请问从类型库添加类向导如何操作,谢谢
cl 2019-09-15
  • 打赏
  • 举报
回复

VS2017打开之后点击项目,之后点击类向导,点击添加类右边的小箭头,选择类型库中的MFC类,进入从类型库添加类向导后,从一下来源添加类,不要选择注册表,选择文件,位置写EXCEL所在的路径,这样可用库就会变成EXCEL的LIB,双击接口添加类即可。
guoqiang5277 2019-06-14
  • 打赏
  • 举报
回复
应该是VS2017里面取消了这个功能。
VS2019里面也取消了这个功能。
秘境之眼 2019-03-02
  • 打赏
  • 举报
回复
可以生成MFCApplication,在生成的过程中,选择添加你需要的基类,然后生成工程,
slowly507 2019-02-27
  • 打赏
  • 举报
回复
引用 5 楼 XiaoZhuzhu45 的回复:
你找到办法了吗
我用VS2015先从类型库添加类,生成各个需要的头文件,然后在拷贝到VS2017里面使用。
slowly507 2019-02-27
  • 打赏
  • 举报
回复
引用 6 楼 XiaoZhuzhu45 的回复:
找到了能给我分享一下吗
我用VS2015先从类型库添加类,生成各个需要的头文件,然后在拷贝到VS2017里面使用。
XiaoZhuzhu45 2019-02-25
  • 打赏
  • 举报
回复
找到了能给我分享一下吗
XiaoZhuzhu45 2019-02-25
  • 打赏
  • 举报
回复
你找到办法了吗
slowly507 2019-01-18
  • 打赏
  • 举报
回复
谢谢,我试试~~
slowly507 2019-01-09
  • 打赏
  • 举报
回复
我现在只能采取用VS2015先从类型库添加类,生成各个需要的头文件,然后在拷贝到VS2017里面使用。 请教有无更好的办法?
worldy 2019-01-09
  • 打赏
  • 举报
回复
使用 #import "C:\...\XXXXX.tlb" \ no_namespace \
zgl7903 2019-01-09
  • 打赏
  • 举报
回复
#import 的方式 哪个版本的VS都可以
VS的例子

// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Visual C++ Language Reference and related
// electronic documentation provided with Microsoft Visual C++.
// See these sources for detailed information regarding the
// Microsoft Visual C++ product.

// NOTE: This example will only work with Excel10 in OfficeXP
// Compile with cl /GX comexcel.cpp
#include "stdafx.h"


#define OFFICE2007 1
#define OFFICEXP 2
#define OFFICE2000 3

// Default Settings
#define OFFICE_VER OFFICE2007
#define USE_PROGID 1
#define USE_LIBID 0

#define _M2STR(x) #x
#define M2STR(x) _M2STR(x)


// Ignore hard wired default paths if MSDLL_PATH is
// defined from the command line
#ifndef MSDLL_PATH

// Paths to required MS OFFICE files.
// Make sure these paths are correct for your machine
#pragma message ("Make sure the path to MSO DLL is correct.")
#if OFFICE_VER == OFFICE2007
#define _MSDLL_PATH "C:\Program Files\Common Files\Microsoft Shared\Office12\MSO.DLL"
#elif OFFICE_VER == OFFICEXP
#define _MSDLL_PATH "C:\Program Files\Common Files\Microsoft Shared\Office11\MSO.DLL"
#elif OFFICE_VER == OFFICE2000
#define _MSDLL_PATH "C:\Program Files\Microsoft Office\Office\MSO9.dll"
#endif

#else
#define _MSDLL_PATH M2STR(MSDLL_PATH)
#endif

//
// Delete the *.tlh files when changing import qualifiers
#import _MSDLL_PATH rename("RGB", "MSRGB")


#ifdef VBE6EXT_PATH
#import M2STR(VBE6EXT_PATH)
#else
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
#endif

#if USE_PROGID
#import "progid:Excel.Sheet" auto_search auto_rename rename_search_namespace("Office12")

#elif USE_LIBID
#import "libid:{00020813-0000-0000-C000-000000000046}" auto_search auto_rename version(1.3) lcid(0) no_search_namespace
#else

// Ignore hard wired default paths if MSDLL_PATH is
// defined from the command line
#ifndef MSEXCEL_PATH

#pragma message ("Make sure the path to excel.exe is correct")
#if OFFICE_VER == OFFICE2007
#define _MSEXCEL_PATH "C:\Program Files\Microsoft Office\Office12\excel.exe"
#elif OFFICE_VER == OFFICEXP
#define _MSEXCEL_PATH "C:\Program Files\Microsoft Office\Office11\excel.exe"
#elif OFFICE_VER == OFFICE2000
#define _MSEXCEL_PATH "C:\Program Files\Microsoft Office\Office\excel.exe"
#endif

#else
#define _MSEXCEL_PATH M2STR(MSEXCEL_PATH)
#endif

#import _MSEXCEL_PATH auto_search auto_rename dual_interfaces
#endif // USE_LIBID



void dump_com_error(_com_error &e)
{
_tprintf(_T("Oops - hit an error!\n"));
_tprintf(_T("\a\tCode = %08lx\n"), e.Error());
_tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}

// If this is placed in the scope of the smart pointers, they must be
// explicitly Release(d) before CoUninitialize() is called. If any reference
// count is non-zero, a protection fault will occur.
struct StartOle {
StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }
} _inst_StartOle;

void main()
{
using namespace Excel;

_ApplicationPtr pXL;

try {
pXL.CreateInstance(L"Excel.Application");

pXL->Visible[0] = VARIANT_TRUE;

WorkbooksPtr pBooks = pXL->Workbooks;
_WorkbookPtr pBook = pBooks->Add((long)xlWorksheet);

_WorksheetPtr pSheet = pXL->ActiveSheet;


try {
// This one will fail; it is done on purpose to demonstrate the error.
pSheet->Name = "Market Share?";
} catch (_com_error &e) {
dump_com_error(e);
}

pSheet->Name = "Market Share!";

// When using parameterized properties, optional args must be explicitly dealt with.
pSheet->Range["A2"][vtMissing]->Value2 = "Company A";
pSheet->Range["B2"][vtMissing]->Value2 = "Company B";
pSheet->Range["C2"][vtMissing]->Value2 = "Company C";
pSheet->Range["D2"][vtMissing]->Value2 = "Company D";

// Of course, you can call a parameterized property as a method and then optional args are implicit.
pSheet->GetRange("A3")->Value2 = 75.0;
pSheet->GetRange("B3")->Value2 = 14.0;
pSheet->GetRange("C3")->Value2 = 7.0;
pSheet->GetRange("D3")->Value2 = 4.0;

Sleep(1000);

RangePtr pRange = pSheet->Range["A2:D3"][vtMissing];
_ChartPtr pChart = pBook->Charts->Add();

pChart->ChartWizard((Range*) pRange, (long) xl3DPie, 7L, (long) xlRows,
1L, 0L, 2L, "Market Share");

Sleep(6000);

pBook->Saved[0] = VARIANT_TRUE;
pXL->Quit();
} catch(_com_error &e) {
dump_com_error(e);
}

}


16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧