COM Spørgsmål
Hej.Jeg prøver at få et meget "simpelt" COM/C#-eksempel til at virke, men det lykkedes bare ikke :( .
Jeg har oprettet en standard win32 dll.
---Win32Dll.h---
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the WIN32DLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// WIN32DLL_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef WIN32DLL_EXPORTS
#define WIN32DLL_API __declspec(dllexport)
#else
#define WIN32DLL_API __declspec(dllimport)
#endif
// This class is exported from the Win32Dll.dll
class WIN32DLL_API CWin32Dll {
public:
CWin32Dll(void);
// TODO: add your methods here.
};
extern WIN32DLL_API int nWin32Dll;
extern WIN32DLL_API int fnWin32Dll(void);
---Win32Dll.cpp---
// Win32Dll.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "Win32Dll.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
// This is an example of an exported variable
WIN32DLL_API int nWin32Dll=0;
// This is an example of an exported function.
extern WIN32DLL_API int fnWin32Dll(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see Win32Dll.h for the class definition
CWin32Dll::CWin32Dll()
{
return;
}
---Program.cs---
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CSharp
{
class Program
{
[DllImport("C:\\Win32\\Win32Dll\\release\\Win32Dll.dll")]
static extern int fnWin32Dll();
static void Main(string[] args)
{
Console.WriteLine(fnWin32Dll());
}
}
}
Problemet er at jeg får følgende exception:
Unable to find an entry point named 'fnWin32Dll' in DLL 'C:\Win32\Win32Dll\release\Win32Dll.dll'.
Hvad har jeg glemt for at metoden bliver synlig?
