How to convert from Platform::String^ to Platform::Guid^ - windows-runtime

It is super easy to go from Platform::Guid^ to Platform::String^ with the ToString() method. See the documentation for more details.
But how do we convert from Platform::String^ to Platform::Guid^?
Edit:
Both CLSIDFromString and IIDFromString will do. Please refer to the accepted answer as an example. Also please #include <wrl\wrappers\corewrappers.h>.

Just call in the help from the IIDFromString() function. Sample code:
Platform::String^ example("{6DDAD7B6-F8C5-42D9-B4EB-59FE94A4EA5F}");
GUID rawguid;
HRESULT hr = IIDFromString(example->Data(), &rawguid);
if (SUCCEEDED(hr)) {
Platform::Guid guid(rawguid);
// etc..
}

Related

Get Name of Message registered by RegisterWindowMessage

I am debugging an old application, where the WndProc is overridden. There I got a message with ID=0xC1B0 which means, that this is a system wide unique message according to this msdn article.
As described by microsoft for the RegisterWindowMessage(...), the same string s the paramter results in the same message-id. So there is an unique link between the message-id and the parameter.
My question is now: Is there a possibility to get the parameter, if I have the message-id? If yes, this might help me to find the source of the message.
As found in the this blog there is no direct way, but the function GetClipboardFormatName(...) gives a work around for the problem.
I used it in the following way:
[DllImport("user32.dll")]
static extern int GetClipboardFormatName(int format, StringBuilder lpszFormatName, int cchMaxCount);
public static string GetMessageName(int msg)
{
var sb = new StringBuilder(256);
GetClipboardFormatName(msg, sb, sb.Capacity);
return sb.ToString();
}

Arduino how to use namespace?

I am using the Arduino IDE to write code and am trying to understand the namespace stuff.
My thought is, is there a way to shorten the many places (in my code) where I have things like:
Serial.print("a="); Serial.print(a); Serial.print(" b="); Serial.println(b);
to something shorter like:
S.print(...
or
sprint(...
Can it be done?
I tried using String concatenation but it is very limited and expensive. That is just adding one
String s;
to my code at the global level increased the download size by 1482 bytes. And you can't do something like:
Serial.print("a=" + a); Serial.println(" b=" + b);
because it cant handle starting a concatenation with a literal string.
Any thoughts welcome.
Arduino uses the C++ language. It is not considered good practice, but you could use a preprocessor macro:
#define sprint Serial.print
You could use a pointer and member de-reference operator, like this:
HardwareSerial *my_device;
void setup()
{
my_device->begin(9600);
delay(100);
}
void loop()
{
if (my_device->available())
{
int r = my_device->read();
// etc.
}
}

powermock #PrepareForTest is not working with wildcard value

Version: powermock-core 1.4.12
Question:
According to the API doc, #PrepareForTest should be able to take wildcard like:
#PrepareForTest("com.smin.*")
But in my case, it's just simply doesn't compile, compile error:
Type mismatch: cannot convert from String to Class<?>[]
I had a look at the source code of PrepareForTest, I just don't see how this annotation can take wildcard as its value. Any ideas?
#Target( { ElementType.TYPE, ElementType.METHOD })
#Retention(RetentionPolicy.RUNTIME)
#Documented
#Inherited
public #interface PrepareForTest {
Class<?>[] value() default IndicateReloadClass.class;
String[] fullyQualifiedNames() default "";
}
Yeah - the docs don't seem to jibe with reality. Try:
#PrepareForTest(fullyQualifiedNames={"com.smin.*"})
I think the resolution of the wildcarded names would happen in the MockClassLoader or it's superclass, DeferSupportingClassLoader, if you feel like digging deeper.

Generic way to get reference to a method's caller?

I have 2 classes representing 2 objects. From the "whoCalledMe" function, I want to find out what object called the function (without passing that information in as an argument). I've used a make-believe property, "caller", that would give me the reference I'm looking for. Is there a generic way I can get a reference to the caller from there?
package {
public class ObjectCallingTheFunction {
public var IDENTITY:String = "I'm the calling function!";
public function ObjectCallingTheFunction() {
var objectWithFunction:ObjectWithFunction = new ObjectWithFunction();
objectWithFunction.whoCalledMe();
}
}
}
package {
public class ObjectWithFunction {
public function whoCalledMe ():void {
trace(caller.IDENTITY); // Outputs: "I'm the calling function!"
}
}
}
It would help to know why you need this, because I have a feeling that you don't really. If the method is anonymous, you can bind the 'this' keyword by using .apply on the method:
var foo:Function = function(arg:int):void
{
trace(this);
};
var bar:Object = {
toString: function():String { return "bar"; }
};
var baz:Object = {
toString: function():String { return "baz"; }
};
foo.apply(bar); // <-- Prints "bar"
foo.apply(baz); // <-- Prints "baz"
If the method is an instance method method however, it's a bound method and thus "this" will always point to the instance of the class it's declared in, no matter if you redefine it by using the apply method. If it's a static method, "this" doesn't make sense and the compiler will catch it.
Other than that, there's really no way short of declaring it as a parameter. There used to be a caller property on the arguments object, but it was deprecated when AS3 was released. You can get a reference to the function itself through arguments.callee, but that's not really what you asked for.
In AS3 you can throw an error and then parse the Stack Trace to find out detailed informations.
You can check here for an example:
http://www.actionscript-flash-guru.com/blog/18-parse-file-package-function-name-from-stack-trace-in-actionscript-as3
If you want to find the called function's name you can follow this example:
http://www.flashontherocks.com/2010/03/12/getting-function-name-in-actionscript-3/
I guess you want to know the caller in debug purpose. if so I would recommend setting a breakpoint in the method/function instead of tracing. When the code breaks you can backtrace the caller and a lot more. Works in Flash IDE as well as Flashbuilder. Google "as3 breakpoints" if you are new to breakpoints.
Here is the official Adobe article on using arguments.callee
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/arguments.html
It includes sample code.
Hope this helps.

custom comparetor in stl

This has been driving me nuts for 3 hours. Anybody see a reason why this isn't working?
struct sortByPropRev
{
bool operator()(const cust_type &a, const cust_type &b) const
{
return a.prop > b.prop;
}
};
...
priority_queue<cust_type, vector<cust_type>, sortByPropRev> x;
I get compile errors:
Error C2664: 'bool (cust_type &,cust_type &)' : cannot convert parameter 1 from 'const cust_type' to 'cust_type &'
and 2 more just like it but on different lines of algorithm.h
You gave it b.pprop, vs a.prop. I think given the error that the compiler failed to parse the struct's definition properly- check for syntax errors in the code just above it.
Never mind. I found the problem. I t was in a different part of the code that was calling the same algorithm functions. Sorry to bother everybody and thanks for trying to help.