我想用c#做一个com组件让delphi调用做了好久都没成功,请大家帮帮忙!
c#代码如下(在c#中调用没问题可以使用):
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;namespace Get_txt
{
[Flags]
public enum IFILTER_INIT : uint
{
NONE = 0,
CANON_PARAGRAPHS = 1,
HARD_LINE_BREAKS = 2,
CANON_HYPHENS = 4,
CANON_SPACES = 8,
APPLY_INDEX_ATTRIBUTES = 16,
APPLY_CRAWL_ATTRIBUTES = 256,
APPLY_OTHER_ATTRIBUTES = 32,
INDEXING_ONLY = 64,
SEARCH_LINKS = 128,
FILTER_OWNED_VALUE_OK = 512
} public enum CHUNK_BREAKTYPE
{
CHUNK_NO_BREAK = 0,
CHUNK_EOW = 1,
CHUNK_EOS = 2,
CHUNK_EOP = 3,
CHUNK_EOC = 4
} [Flags]
public enum CHUNKSTATE
{
CHUNK_TEXT = 0x1,
CHUNK_VALUE = 0x2,
CHUNK_FILTER_OWNED_VALUE = 0x4
} [StructLayout(LayoutKind.Sequential)]
public struct PROPSPEC
{
public uint ulKind;
public uint propid;
public IntPtr lpwstr;
} [StructLayout(LayoutKind.Sequential)]
public struct FULLPROPSPEC
{
public Guid guidPropSet;
public PROPSPEC psProperty;
} [StructLayout(LayoutKind.Sequential)]
public struct STAT_CHUNK
{
public uint idChunk;
[MarshalAs(UnmanagedType.U4)] public CHUNK_BREAKTYPE breakType;
[MarshalAs(UnmanagedType.U4)] public CHUNKSTATE flags;
public uint locale;
[MarshalAs(UnmanagedType.Struct)] public FULLPROPSPEC attribute;
public uint idChunkSource;
public uint cwcStartSource;
public uint cwcLenSource;
} [StructLayout(LayoutKind.Sequential)]
public struct FILTERREGION
{
public uint idChunk;
public uint cwcStart;
public uint cwcExtent;
} [ComImport]
[Guid("89BCB740-6119-101A-BCB7-00DD010655AF")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IFilter
{
[PreserveSig]
int Init([MarshalAs(UnmanagedType.U4)] IFILTER_INIT grfFlags, uint cAttributes, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] FULLPROPSPEC[] aAttributes, ref uint pdwFlags); [PreserveSig]
int GetChunk(out STAT_CHUNK pStat); [PreserveSig]
int GetText(ref uint pcwcBuffer, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer); void GetValue(ref UIntPtr ppPropValue);
void BindRegion([MarshalAs(UnmanagedType.Struct)] FILTERREGION origPos, ref Guid riid, ref UIntPtr ppunk);
} [ComImport]
[Guid("f07f3920-7b8c-11cf-9be8-00aa004b9986")]
public class CFilter
{
} public class IFilterConstants
{
public const uint PID_STG_DIRECTORY = 0x00000002;
public const uint PID_STG_CLASSID = 0x00000003;
public const uint PID_STG_STORAGETYPE = 0x00000004;
public const uint PID_STG_VOLUME_ID = 0x00000005;
public const uint PID_STG_PARENT_WORKID = 0x00000006;
public const uint PID_STG_SECONDARYSTORE = 0x00000007;
public const uint PID_STG_FILEINDEX = 0x00000008;
public const uint PID_STG_LASTCHANGEUSN = 0x00000009;
public const uint PID_STG_NAME = 0x0000000a;
public const uint PID_STG_PATH = 0x0000000b;
public const uint PID_STG_SIZE = 0x0000000c;
public const uint PID_STG_ATTRIBUTES = 0x0000000d;
public const uint PID_STG_WRITETIME = 0x0000000e;
public const uint PID_STG_CREATETIME = 0x0000000f;
public const uint PID_STG_ACCESSTIME = 0x00000010;
public const uint PID_STG_CHANGETIME = 0x00000011;
public const uint PID_STG_CONTENTS = 0x00000013;
public const uint PID_STG_SHORTNAME = 0x00000014;
public const int FILTER_E_END_OF_CHUNKS = (unchecked((int) 0x80041700));
public const int FILTER_E_NO_MORE_TEXT = (unchecked((int) 0x80041701));
public const int FILTER_E_NO_MORE_VALUES = (unchecked((int) 0x80041702));
public const int FILTER_E_NO_TEXT = (unchecked((int) 0x80041705));
public const int FILTER_E_NO_VALUES = (unchecked((int) 0x80041706));
public const int FILTER_S_LAST_TEXT = (unchecked((int) 0x00041709));
} /// 
/// IFilter return codes
/// 
public enum IFilterReturnCodes : uint
{
/// 
/// Success
/// 
S_OK = 0,
/// 
/// The function was denied access to the filter file. 
/// 
E_ACCESSDENIED = 0x80070005,
/// 
/// The function encountered an invalid handle, probably due to a low-memory situation. 
/// 
E_HANDLE = 0x80070006,
/// 
/// The function received an invalid parameter.
/// 
E_INVALIDARG = 0x80070057,
/// 
/// Out of memory
/// 
E_OUTOFMEMORY = 0x8007000E,
/// 
/// Not implemented
/// 
E_NOTIMPL = 0x80004001,
/// 
/// Unknown error
/// 
E_FAIL = 0x80000008,
/// 
/// File not filtered due to password protection
/// 
FILTER_E_PASSWORD = 0x8004170B,
/// 
/// The document format is not recognised by the filter
/// 
FILTER_E_UNKNOWNFORMAT = 0x8004170C,
/// 
/// No text in current chunk
/// 
FILTER_E_NO_TEXT = 0x80041705,
/// 
/// No more chunks of text available in object
/// 
FILTER_E_END_OF_CHUNKS = 0x80041700,
/// 
/// No more text available in chunk
/// 
FILTER_E_NO_MORE_TEXT = 0x80041701,
/// 
/// No more property values available in chunk
/// 
FILTER_E_NO_MORE_VALUES = 0x80041702,
/// 
/// Unable to access object
/// 
FILTER_E_ACCESS = 0x80041703,
/// 
/// Moniker doesn't cover entire region
/// 
FILTER_W_MONIKER_CLIPPED = 0x00041704,
/// 
/// Unable to bind IFilter for embedded object
/// 
FILTER_E_EMBEDDING_UNAVAILABLE = 0x80041707,
/// 
/// Unable to bind IFilter for linked object
/// 
FILTER_E_LINK_UNAVAILABLE = 0x80041708,
/// 
/// This is the last text in the current chunk
/// 
FILTER_S_LAST_TEXT = 0x00041709,
/// 
/// This is the last value in the current chunk
/// 
FILTER_S_LAST_VALUES = 0x0004170A
} /// 
/// Convenience class which provides static methods to extract text from files using installed IFilters
/// 

解决方案 »

  1.   

    编译成a.dll,拷贝到c:/windows/system32下,开始——运行a.dll
      

  2.   

    制作过程很简单,像普通的C# DLL就行
    注册麻烦点:
    Regasm abc.dll /tlb:abc.tlb /codebase
      

  3.   

    组件调用是无关语言的。c#写的dll,直接编译成*.dll就行.dephi里面该如何调用就如何调吧。
      

  4.   

    dll是通用的,编译器不同不会有太多不同的~~~~
    不过用传统的查看资源的软件会看不到C#中dll的导出函数的~~~~另外你说你想做脱离.net框架的C#程序?
    只能很可惜的告诉你,不可能~~~
      

  5.   

    普通c#的.dll是委托执行的需要.net框架的支持
    我查到过写com组件在没有.net框架的系统中供asp调用
    可是我就是弄不成功希望有经验的朋友帮帮忙!
      

  6.   

    C#做不了不南非要.net框架支持的玩意儿,那要用VB或VC
      

  7.   

    那大家谁做过这样的组件!
    功能:提取office系列文件文本内容
    给一个也可以不过要求delphi能调用
      

  8.   

    ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconexposingnetframeworkcomponentstocom.htm
      

  9.   

    想做脱离.net框架的C#程序?
    不可能~~~也许你该换delphi.net