Winapi //抵消。 捕获(异常^eResult) { itemNum--; offset++; } } //让我看看钱! 对于(int i=1;i计数偏移量);(i++) printf(“%d-%s\n”,i,邮件[i]->主题); } olNs->Logoff(); 返回0; }

Winapi //抵消。 捕获(异常^eResult) { itemNum--; offset++; } } //让我看看钱! 对于(int i=1;i计数偏移量);(i++) printf(“%d-%s\n”,i,邮件[i]->主题); } olNs->Logoff(); 返回0; },winapi,x86,64-bit,mapi,loadlibrary,Winapi,X86,64 Bit,Mapi,Loadlibrary,现在我知道怎么进去了,我可以继续完成我的项目了!谢谢大家的帮助 干杯! d您阅读的设置(x86、x64和任何CPU)肯定是针对C#或VB.NET中的托管代码的。这些不适用于VisualC++,在这里你应该看到Win32(即x86)和x64(还有一堆其他不相关的选项)。对不起,我现在正用C++和CLI和.NET来润湿我的脚。我只是习惯于说VC++。。。是的,我正在使用托管代码,目标是CLR。就在我认为我精通C++的时候,Boo.!我被.NET卡车辗过了!总之,你是说对于我的项目类型,我应该只看到W

现在我知道怎么进去了,我可以继续完成我的项目了!谢谢大家的帮助

干杯!
d

您阅读的设置(x86、x64和任何CPU)肯定是针对C#或VB.NET中的托管代码的。这些不适用于VisualC++,在这里你应该看到Win32(即x86)和x64(还有一堆其他不相关的选项)。对不起,我现在正用C++和CLI和.NET来润湿我的脚。我只是习惯于说VC++。。。是的,我正在使用托管代码,目标是CLR。就在我认为我精通C++的时候,Boo.!我被.NET卡车辗过了!总之,你是说对于我的项目类型,我应该只看到Win32、x64和其他一些奇怪的选项?我只看到Win32,但如果我去添加/删除VS2008的功能,它显示我在VC++下安装了“X64编译器和工具”。我应该担心吗?谢谢,科迪!除了他似乎在使用Office12之外,它在64位版本中不可用。因此,32位版本的Office和32位版本的MAPI DLL应该可以在64位Windows上正常工作。@Cody Gray:是的,如果没有64位版本的Office,他唯一的选择就是使用32位版本的MAPI,这是我们多年来一直在做的。谢谢,Sharptooth!我实际上安装了office 2010 x64,但我的PIA(\Program Files(x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for office\PIA\Office12\)是v.12。我想它们是当年我使用Office2007时的产物。到目前为止,它们仍然可以通过编程方式与我的2010安装配合使用,而且由于这个应用程序也需要与2007配合使用,我认为我应该坚持使用这些PIA。但无论如何,看看我对bryanbcook的回复;我错误地认为这是一个咬的问题,所以我现在要去弄清楚这个问题。再次感谢!默认情况下不安装64位编译器。重新运行安装程序,选择“自定义”。重新应用SP1。否则不会解释错误193,很难相信他找到了64位版本的olmapi32.dllWell darnit!我似乎在匆忙地假设错误193是由于我的exe是64位的。你们是对的-它是32位的。我刚刚运行了exe并查看了taskman,看看它旁边确实有“*32”。对不起,各位,我应该先检查一下。(为我辩护,已经很晚了:))。所以现在我想我有一个不同的问题要解决。我想正确的做法是开始一个新的问题,但首先我应该尽我的职责,在我再次打扰你们之前,试着自己解决这个问题。(当然,欢迎任何想法!)谢谢!
using namespace System;
using namespace Microsoft::Office::Interop;
using namespace Microsoft::Win32;

int main(array<System::String ^> ^args)
{
    RegistryKey^ subK = Registry::LocalMachine->OpenSubKey("SOFTWARE\\Clients\\Mail\\Microsoft Outlook");
    String^ mailDll = safe_cast<String^>(subK->GetValue("DLLPathEx"));
    CStringW cStrMailDll = mailDll; //Just to put mailDll in a format that LoadLibrary() can read.

    LPMAPIINITIALIZE mapiInit = NULL;

    HMODULE mapiLib = LoadLibrary(cStrMailDll); // This Returns NULL
    if(mapiLib == NULL)
    {
        printf("\nError: %d\n", GetLastError()); // System Error 193 - ERROR_BAD_EXE_FORMAT
        return 1;
    }

    ...(more code)
    ...
#define nul Reflection::Missing::Value
#include "stdafx.h"
using namespace System;
using namespace Microsoft::Office::Interop;

int main(array<System::String ^> ^args)
{
    // Create the outlook object
    Outlook::Application^ olApp = gcnew Outlook::Application();

    // Get an instance of the MAPI namespace via the outlook object
    Outlook::NameSpace^ olNs = olApp->GetNamespace("MAPI");

    // Log this instance into the MAPI interface
    // Note that this will cause the user to be prompted for which profile
    // to use. At least, it prompts me, and I only have one profile anyway. Whatever.
    // Change the first argument to the name of the profile you want it to use (String)
    // to bypass this prompt. I personally have mine set to "Outlook".
    olNs->Logon(nul, nul, true, true);

    // Get my Inbox
    Outlook::Folder^ defFolder = safe_cast<Outlook::Folder^>(olNs->GetDefaultFolder(Outlook::OlDefaultFolders::olFolderInbox));

    // Get all of the items in the folder (messages, meeting notices, etc.)
    Outlook::Items^ fItems = defFolder->Items;

    // Sort them according to when they were received, descending order (most recent first)
    fItems->Sort("[ReceivedTime]", true);

    // Show me the folder name, and how many items are in it
    printf("\n%s: %d\n", defFolder->Name, fItems->Count);

    // Make an array of _MailItems to hold the messages.
    // Note that this is a _MailItem array, so it will only hold email messages.
    // Other item types (in my case, meeting notices) cannot be added to this array.
    array<Outlook::_MailItem^>^ mail = gcnew array<Outlook::_MailItem^>(fItems->Count);

    int itemNum = 1;
    int offset = 0;

    // If there's anything in my Inbox, do the following...
    if(fItems->Count)
    {
        // Try to grab the first email with "fItems->GetFirst()", and increment itemNum.
        try
        {
            mail[itemNum++] = safe_cast<Outlook::_MailItem^>(fItems->GetFirst());
        }
        // If it threw an exception, it's probably because the item isn't a _MailItem type.
        // Since nothing got assigned to mail[1], reset itemNum to 1
        catch(Exception^ eResult)
        {
            itemNum = 1;
        }

        // Ok, now use "fItems->GetNext()" to grab the rest of the messages
        for(; itemNum <= (fItems->Count-offset); itemNum++)
        {
            try
            {
                mail[itemNum] = safe_cast<Outlook::_MailItem^>(fItems->GetNext());
            }
            // If it puked, then nothing got assigned to mail[itemNum]. On the next iteration of
            // this for-loop, itemNum will be incremented, which means that *this* particular index
            // of the mail array would be left empty. To prevent this, decrement itemNum.
            // Also, if itemNum ever gets decremented, then that will ultimately cause this loop
            // to iterate more times than fItems->Count, causing an out-of-bounds error. To prevent
            // that, increment "offset" each time you decrement "itemNum" to compensate for the
            // offset.
            catch(Exception^ eResult)
            {
                itemNum--;
                offset++;
            }
        }

        // Show me the money!
        for(int i=1; i <= (fItems->Count-offset); i++)
            printf("%d - %s\n", i, mail[i]->Subject);
    }

    olNs->Logoff();
    return 0;
}