如何从[C#WP8.1 WRT / SL]项目中调用[Unmanaged C ++ DLL func](How to Call [Unmanaged C++ DLL func] from [C# WP8.1 WRT/SL] project)
这不是“如何从C#调用C ++函数”的重复
我知道如何为普通的PC应用程序做到这一点,我尝试过,它的工作原理:
这称为P / Invoke
1. Create a C++ dll project, but you can't add the C++ dll project as a reference to the C# project. Copy the dll from C++, and paste the dll to the C# exe folder 2. in C# use [DllImport...] in C++ use extern "C" __declspec(dllexport) ...
但是当我在WindowsPhone上这样做时,失败了。
有2种类型的非托管c + +原生dll项目的Windows Phone,我都尝试过
DLL (Windows Phone) <- WRT DLL 8.1 DLL (Windows Phone Silverlight 8.1)
我不知道在哪里放置dll文件。 因为最后的exe是一个包。 我不能将dll放在与包相同的文件夹中。 作为软件包的一部分,该DLL应该位于软件包中。
所以我试图在C#WP8.1 SL项目中添加dll作为resorce文件。
但函数调用失败。
所以我想知道的是,如何放置dll,如何使用WP8.1 SL项目来连接dll?
有没有人尝试过吗?
谢谢你们的答案。
// ------------------------------------------------ ------------
所以正确的方法是对于[C#WP8.1 SL]项目,我需要
create a [C++ Runtime Component DLL] <- as bridge create a [C++ Native WP SL DLL] <- real dll Add the [C++ Runtime Component DLL] as a reference to [C# WP8.1 SL] And the [C++ Native WP SL DLL] as a reference to [C++ Runtime Component DLL]
This is not a duplicate of "how to call C++ function from C#"
I know how to do it for regular PC app and I tried and it works:
This is called P/Invoke
1. Create a C++ dll project, but you can't add the C++ dll project as a reference to the C# project. Copy the dll from C++, and paste the dll to the C# exe folder 2. in C# use [DllImport...] in C++ use extern "C" __declspec(dllexport) ...
But when I do this on WindowsPhone, failed.
There are 2 type of unmanaged c++ native dll project for windows phone, I tried both
DLL (Windows Phone) <- WRT DLL 8.1 DLL (Windows Phone Silverlight 8.1)
I don't know where to place the dll file. Because the finally exe is a package. I can't place the dll in the same folder with the package. The dll should be in the package, as a part of the package.
So I tried to add the dll as a resorce file in the C# WP8.1 SL project.
But the function call failed.
So what I want to know is, how to place the dll, how to hook up the dll with the WP8.1 SL project?
Is there any one try that before?
Thank you guys for the answer.
//------------------------------------------------------------
So the correct way is For a [C# WP8.1 SL] project, I need to
create a [C++ Runtime Component DLL] <- as bridge create a [C++ Native WP SL DLL] <- real dll Add the [C++ Runtime Component DLL] as a reference to [C# WP8.1 SL] And the [C++ Native WP SL DLL] as a reference to [C++ Runtime Component DLL]
原文:https://stackoverflow.com/questions/29761538
最满意答案
id1
和id2
实际上是NSString
,即使它们被转换为id
并传递给你的函数(这种方法很有用,因为你可以定义你的compare
函数来排序自定义对象)。在字符串上调用
stringValue
是没有意义的(实际上,NSString
没有名为stringValue
的成员函数)。使用字符串只是
NSString
为NSString
。NSString *s1 = (NSString*) id1; NSString *s2 = (NSString*) id2;
这不是绝对必要的(你甚至可以直接使用
id1
和id2
)但是转换会避免你得到编译器警告(也是一个更清晰的代码)。
id1
andid2
are actuallyNSString
s, even if they are casted toid
and passed to your function (this approach is useful because you can define yourcompare
function in order to sort custom objects).It doesn't make sense to call
stringValue
on a string (and, in fact,NSString
do not have a member function namedstringValue
).To work with strings just cast back to
NSString
s.NSString *s1 = (NSString*) id1; NSString *s2 = (NSString*) id2;
This is not strictly necessary (you can even work directly with
id1
andid2
) but casting will avoid you to get compiler warnings (also it's a clearer code).
相关问答
更多-
id1和id2实际上是NSString ,即使它们被转换为id并传递给你的函数(这种方法很有用,因为你可以定义你的compare函数来排序自定义对象)。 在字符串上调用stringValue是没有意义的(实际上, NSString没有名为stringValue的成员函数)。 使用字符串只是NSString为NSString 。 NSString *s1 = (NSString*) id1; NSString *s2 = (NSString*) id2; 这不是绝对必要的(你甚至可以直接使用id1和id2 ...
-
@property (copy)的合成设置器向数组发送copy消息,这将导致不可变的副本。 你别无选择,只能在这里实现设置者,如Objective-C指南中所述。 I would like to tip my hat to Georg Fritzsche. I did end up needing to use (copy) instead of (retain), and I would not have known what to do without his input. //@property (c ...
-
[__NSCFString superview]:发送到实例的无法识别的选择器([__NSCFString superview]: unrecognized selector sent to instance)[2022-07-30]
应用程序中的某个位置是获取的NSString对象的超级视图。 我猜你已经为一个需要UIView的东西分配了一个NSString对象。 可能是这样的: someButton.textLabel = someString; // wrong - but should generate a compiler warning 代替 someButton.textLabel.text = someString; // correct 这与您的阵列问题没有直接关系。 Somewhere in your App is ... -
cell.imageView.image = _flowerData[indexPath.section][indexPath.row][@"picture"]; 这行cell.imageView.image期望UIImage类型 [redFlowers addObject:@{@"name":@"Gerbera",@"picture":@"Gerbera.png",@"url":@"http://en.wikiepdia.org/wiki/Gerbera"}]; 但你在这里给它一个NSString , ...
-
我犯的错误是在handleSearchForTerm函数。 我使用NSMutableArray *数组来保存我的Periods对象的值,然后我将数组添加到我的searchResults数组(期望searchResults持有Periods)。 解决方案就像将Periods直接添加到我的searchResults数组和ditching数组一样简单...... The error I was making was at the handleSearchForTerm function. I was using ...
-
-copy返回不可变对象,即使您在可变数组上调用它也是如此。 要获得可变副本,您必须调用mutableCopy方法: -(id)initWithTerm:(NSString *)thisTerm andPrevResults:(NSMutableArray *)aPrevResults { ... self.aFinals = [aPrevResults mutableCopy]; ... } 此外,由于您正在使用保留属性,因此您需要补偿额外的增量以保留副本上发生的计数: se ...
-
结果是我的cellForRowAtIndexPath上的拼写错误 -(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector { self.collation = [UILocalizedIndexedCollation currentCollation]; NSInteger sectionCount = [[self.collation sectionTitles] count]; ...
-
看起来你在NSSrr上使用了NSArray的count方法,这是不允许的。 您将NSStrings存储在searchProfile数组中,看起来您想要找出字符串的长度。 所以不是这样的: rows = [[searchedProfile objectAtIndex:section] count]; 做这个: rows = [[searchedProfile objectAtIndex:section] length]; It looks like you're using the cou ...
-
NSDictionary长度:发送到实例的无法识别的选择器(NSDictionary length :unrecognized selector sent to instance)[2022-07-31]
- [__ NSDictionaryI length]:无法识别的选择器发送到实例 此消息告诉您NSDictionary (或者,特别是私有不可变子类__NSDictionaryI )接收到对length方法的调用,它不响应。 'length'是调用字符串的常用方法,所以这是一个相当安全的赌注,即抛出异常的代码所期望的。 NSData也有一个length方法,但这似乎不太可能基于您的代码。 您需要单步执行代码以查找字典的位置,但代码需要字符串(或数据)。 -[__NSDictionaryI length]: ... -
无法识别的选择器发送到NSKeyedUnarchiver的实例(unrecognized selector sent to instance for NSKeyedUnarchiver)[2021-07-16]
错误消息显示 Thecontacts = [valueDictionary objectForKey:@"Contacts"]; 返回NSString对象,而不是您期望的NSData对象。 我假设您使用类似的东西创建了JSON [NSString stringWithFormat:@"%@", Contacts] 它使用NSData的description方法并返回一个字符串 <62706c69 73743030 d4010203 0405082b ... > 或者也许SBJson隐含地这样做了。 您 ...