开发者

string parameters not being passed in Release mode

I have a C++/CLI library build with VS2008 that uses marshal_as to convert System::String method parameters into std::string types to pass into a native pointer's method parameters. The code looks very similar to this:

System::Void QueryContext::SetNamespace(String^ prefix, String^ uri)
{
  std::string _prefix; 
  if (nullptr != prefix) 
  { 
    _prefix = marshal_as<std::string>(prefix);
  }
  std::string _ns; 
  if (nullptr != uri) 
  { 
    _ns = marshal_as<std::string>(uri);
  }
  // at this point both variables are confirmed to have values 
  // at least from within the Locals view in the debugger
  _ctx->setNamespace(_prefix,_ns);
}

This code is being compiled for th开发者_开发技巧e x64 platform.

The problem I'm currently having is this: when the code is built in Debug mode, it runs without any problems. When the code is built in Release mode, the native pointer (_ctx) throws an exception basically saying that there is no value assigned to variable _ns, despite the fact that I've been able to confirm in the debugger that the value is indeed there.

In other words, the native code runs fine in Debug mode, but in Release mode it fails because the values appear blank inside the native code.

Is there something going on in Release mode, or with the marshal_as template, that is causing problems here? Has anyone run into this kind of problem before?

Thanks!


Turns out the Release library was linked to the Multi-Threaded Debug DLL (/MDd) in the C++->Code Generation settings, as opposed to the correct Multi-Threaded DLL (/MD) in the project settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜