c#调用c++ 尝试读取或写入受保护的内存

hu_service 2013-11-05 08:59:31
c#调用c++ 尝试读取或写入受保护的内存,怎么解决

c++ API:

void MD_InitMessageInfo(
MD_MessageInfo* MessageInfo // pointer to MD_MessageInfo struct
)

The MD_InitMessageInfo structure initializes an MD_MessageInfo structure in
preparation for sending an email message using MD_SpoolMessage.

Parameters

MessageInfo - pointer to an MD_MessageInfo structure. This members of this
structure are cleared and the priority member is set to
MD_PRECEDENCE_NORMAL.

Remarks

You should call this function immediately after declaring an MD_MessageInfo
structure.

Example

MD_MessageInfo MessageInfo;
MD_InitMessageInfo(&MessageInfo);



c# API

MDUser.InitMessageInfo MessageInfo

This method initializes the MessageInfo object in preparation for sending an email message
using MDUser.SpoolMessage.

Parameters

MessageInfo - MDMessageInfo ojbect. The priority attribute is set to
MD_PRECEDENCE_NORMAL.

Remarks

You should call this method immediately after creating an instance of the MDMessageInfo object.



 MDUser mdu = new MDUser();
MDMessageInfo MessageInfo = new MDMessageInfo();

MessageInfo.To = "test1@ceshi.com";
MessageInfo.From = "test2@ceshi.com";
MessageInfo.Subject = "邮件主题";
MessageInfo.MessageBody = "邮件正文内容";

mdu.InitMessageInfo(MessageInfo);



程序运行到 InitMessageInfo 异常:尝试读取或写入受保护的内存

...全文
243 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hu_service 2013-11-06
  • 打赏
  • 举报
回复
没人给解决了,
hu_service 2013-11-05
  • 打赏
  • 举报
回复
没人了怎么。。。
hu_service 2013-11-05
  • 打赏
  • 举报
回复
引用 5 楼 yuekunge 的回复:
[quote=引用 4 楼 hu_service 的回复:] [quote=引用 3 楼 yuekunge 的回复:] 参数错误···
不懂c++,具体该怎么调用在c#中[/quote] 意思就是 C++和C#的参数要对应啦··· 结构参数 一般都加上 ref··[/quote]
 MDUser mdu = new MDUser();
            MDMessageInfo MessageInfo = new MDMessageInfo();

            MessageInfo.To = "test1@ceshi.com";
            MessageInfo.From = "test2@ceshi.com";
            MessageInfo.Subject = "邮件主题";
            MessageInfo.MessageBody = "邮件正文内容";

            mdu.InitMessageInfo(MessageInfo);
这段代码要怎么写才正确。。
敌敌畏耶 2013-11-05
  • 打赏
  • 举报
回复
引用 4 楼 hu_service 的回复:
[quote=引用 3 楼 yuekunge 的回复:] 参数错误···
不懂c++,具体该怎么调用在c#中[/quote] 意思就是 C++和C#的参数要对应啦··· 结构参数 一般都加上 ref··
hu_service 2013-11-05
  • 打赏
  • 举报
回复
引用 3 楼 yuekunge 的回复:
参数错误···
不懂c++,具体该怎么调用在c#中
敌敌畏耶 2013-11-05
  • 打赏
  • 举报
回复
参数错误···
hu_service 2013-11-05
  • 打赏
  • 举报
回复
#define MDUSERDLL_MAXMSGTO_LEN        128
#define MDUSERDLL_MAXMSGFROM_LEN      128
#define MDUSERDLL_MAXMSGSUBJECT_LEN   128
#define MDUSERDLL_MAXCONTENTTYPE_LEN  128
#define MDUSERDLL_MAXCHARSET_LEN       30
#define MDUSERDLL_MAXMSGBODY_LEN     5001

struct MD_MessageInfo
  {
    char To[MDUSERDLL_MAXMSGTO_LEN+1];
    char From[MDUSERDLL_MAXMSGFROM_LEN+1];
    char Subject[MDUSERDLL_MAXMSGSUBJECT_LEN+1];
    char ContentType[MDUSERDLL_MAXCONTENTTYPE_LEN+1];
    char CharSet[MDUSERDLL_MAXCHARSET_LEN+1];

    char MessageBody[MDUSERDLL_MAXMSGBODY_LEN+1];
    char BodyFilePath[MAX_PATH+1];

    char AttachmentFilePath[MAX_PATH+1];
    bool RemoveAttachment;

    int Priority;
  };
hu_service 2013-11-05
  • 打赏
  • 举报
回复
--------------------
MDMessageInfo Object
--------------------

MDUSERDLL_MAXMSGTO_LEN      128
MDUSERDLL_MAXMSGFROM_LEN    128
MDUSERDLL_MAXMSGSUBJECT_LEN 128
MDUSERDLL_MAXMSGBODY_LEN    2048

Properties:

    To	- String value, max length is MDUSERDLL_MAXMSGTO_LEN
    From	- String value, max length is MDUSERDLL_MAXMSGFROM_LEN
    Subject	- String value, max length is MDUSERDLL_MAXMSGSUBJECT_LEN
    MessageBody	- String value, max length is MDUSERDLL_MAXMSGBODY_LEN
    BodyFilePath	- String value, max length is 255
    AttachmentFilePath	- String value, max length is 255
    RemoveAttachment	- Boolean value
	Priority	- Long value

Field Descriptions

  To - this field contains the name of the recipient of the email message.
    It can contain any value which MDaemon allows within the TO header of a
    RAW format message (see MDaemon manual for details)

  From - this field contains the name of the sender of the email message.
    It can contain any value which MDaemon allows within the FROM header of a
    RAW format message (see MDaemon manual for details)

  Subject - this field contains the subject of the email message.

  MessageBody - this field contains the text of the message body.

  BodyFilePath - this field contains the path to a text file that should be
    used as the message body. After calling MD_SpoolMessage you should remove
    this file.

  AttachmentFilePath - this field contains the path to a single file on disk
    which should be encoded and attached to the message.

  RemoveAttachment - if TRUE the file specified in AttachmentFilePath will be
    removed from disk once the message has been converted for sending by
    MDaemon.

  Priority - this field specifies the relative importance of this message.

  ContentType - this field specifies the content type, ie. 'text/html'

  CharSet - this field specifies the character set, ie. 'iso-8859-1' 

Remarks

  The MessageBody field has a maximum length of MDUSERDLL_MAXMSGBODY_LEN
  chars.  If this is not enough space the text should be placed in a separate
  disk file and the BodyFilePath field should be used.  Note that both can
  be used in the same structure.  So, you can specify up to
  MDUSERDLL_MAXMSGBODY_LEN chars in the MessageBody field and place the rest
  in a text file for use with the BodyFilePath field.

  Only a single file can be specified in the AttachmentFilePath field.

  The RemoveAttachment field does not cause the attached file to be removed
  immediately.  The file is removed by MDaemon once the RAW message is
  converted and fully prepared for delivery.  This is done by MDaemon when
  the RAW queue is processed.

  The Priority field can contain any one of the following values:

  MD_PRECEDENCE_URGENT   // an extremely important message
  MD_PRECEDENCE_HIGH     // a message that is more important than normal
  MD_PRECEDENCE_NORMAL   // this is the default for normal mail
  MD_PRECEDENCE_LOW      // some system or robot generated mail
  MD_PRECEDENCE_BULK     // default mailing list mail
  MD_PRECEDENCE_RETRY    // messages in the retry queue

Methods:
None
hu_service 2013-11-05
  • 打赏
  • 举报
回复
ftp://221.12.68.155/123/mddsf/Docs/API/MDUserImports.h
hu_service 2013-11-05
  • 打赏
  • 举报
回复
引用 11 楼 sololie 的回复:
InitMessageInfo成员函数声明的地方也要标记ref
http://download.csdn.net/detail/hu_service/6505177 这是Dll文件,和API文档。麻烦抽几分钟时间给看下吧,调用这个C++ 折磨一上午了,搞不明白。 非常感谢。
sololie 2013-11-05
  • 打赏
  • 举报
回复
InitMessageInfo成员函数声明的地方也要标记ref
hu_service 2013-11-05
  • 打赏
  • 举报
回复
引用 8 楼 sololie 的回复:

MDUser mdu = new MDUser();
MDMessageInfo MessageInfo = new MDMessageInfo();

MessageInfo.To = "test1@ceshi.com";
MessageInfo.From = "test2@ceshi.com";
MessageInfo.Subject = "邮件主题";
MessageInfo.MessageBody = "邮件正文内容";
// The priority attribute is set to MD_PRECEDENCE_NORMAL.
MessageInfo.Priority = MD_PRECEDENCE_NORMAL; // 自己在接口文档中找这个常量的定义

mdu.InitMessageInfo(ref MessageInfo); // 标记 ref 
mdu.InitMessageInfo(ref MessageInfo); // 标记 ref 不可标记ref,报错,最匹配的重载方法具有一些无效参数
sololie 2013-11-05
  • 打赏
  • 举报
回复
更多关于向非托管代码传递指针的说明 http://www.cnblogs.com/lihuixian001/archive/2013/03/02/2939712.html
sololie 2013-11-05
  • 打赏
  • 举报
回复

MDUser mdu = new MDUser();
MDMessageInfo MessageInfo = new MDMessageInfo();

MessageInfo.To = "test1@ceshi.com";
MessageInfo.From = "test2@ceshi.com";
MessageInfo.Subject = "邮件主题";
MessageInfo.MessageBody = "邮件正文内容";
// The priority attribute is set to MD_PRECEDENCE_NORMAL.
MessageInfo.Priority = MD_PRECEDENCE_NORMAL; // 自己在接口文档中找这个常量的定义

mdu.InitMessageInfo(ref MessageInfo); // 标记 ref 

8,834

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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