IDL file incompatibility with vS2010 - visual-studio-2010

I've migrated COM projects from VS2013 to VC2010 then encountered into one issue. In VC10 few method's signature is changed so header file generated is compatible with VC10 but not with VS13.
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IFileStr * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
__RPC__deref_out void **ppvObject);
In the third parameter "__RPC__deref_out" is getting added
and the one generated using VS2013 is like,
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IFileStr * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */
__COM_Outptr void **ppvObject);
Can any one suggest?

Related

MDItem Class In Xamarin

I'm trying to read comment field from file.
Found this thread about how to do it, but can't find MDItem corresponding class in Xamarin.
Any ideas where to find it or what to use instead?
Some of the CoreServices are not wrapped within the current Xamarin.Mac
(Version: 2.10.0.57).
Most of them pass CFxxxx-based references around, so they are easy to wrap and implement via some Interop calls.
Finder-based File comment
Code Example:
var fileURL = NSUrl.FromString("/Users/sushi/Desktop/DFeedback_FeedBack.png");
var mMDItemRef = MDItemCreateWithURL(IntPtr.Zero, fileURL.Handle);
var mCFTypeRef = MDItemCopyAttribute(mMDItemRef, new CFString("kMDItemFinderComment").Handle);
var finderComment = NSString.FromHandle(mCFTypeRef);
Console.WriteLine(finderComment);
Note: The interop calls should be tested for null in production code, see return signature comments in header file.
Application Output:
StackOverflow
Interop setup:
// #function MDItemCreateWithURL
// Returns an metadata item for the given path.
// #param allocator The CFAllocator which should be used to allocate
// memory for the query and its sub-storage.This
// parameter may be NULL in which case the current default
// CFAllocator is used.
// #param url A url to the file for which to create the MDItem.
// [[Currently, the file must exist.MDItemRefs may or
// may not be uniqued.Use CFEqual() to compare them.]]
// #result An MDItemRef, or NULL on failure.
//MD_EXPORT MDItemRef MDItemCreateWithURL(CFAllocatorRef allocator, CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
[DllImport(Constants.CoreServicesLibrary)]
extern static /* MDItemRef */ IntPtr MDItemCreateWithURL(/* CFAllocatorRef __nullable */ IntPtr allocator, /* CFURLRef */ IntPtr inURL);
//#function MDItemCopyAttribute
//Returns the value of the given attribute for the item.
//#param item The item to be interrogated.
//#param name The name of the desired attribute.
//#result A CFTypeRef, or NULL on failure, or if the attribute
//does not exist, of if the attribute is not readable.
//MD_EXPORT CFTypeRef MDItemCopyAttribute(MDItemRef item, CFStringRef name) MD_AVAIL;
[DllImport(Constants.CoreServicesLibrary)]
extern static /* CFTypeRef */ IntPtr MDItemCopyAttribute(/* MDItemRef */ IntPtr item, /* CFStringRef */ IntPtr name);
Xcode Obj-C Header Reference:
MDItem.h
Local Xcode Ref:: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Headers

boost asio and libcurl mutiple handler

im learning libcurl and boost:asio from this nice post http://www.lijoantony.com/?p=76
though i do have one question about the source code at:
sample code
the main function looks like:
int main(int argc, char **argv)
{
GlobalInfo g;
CURLMcode rc;
(void)argc;
(void)argv;
memset(&g, 0, sizeof(GlobalInfo));
g.multi = curl_multi_init();
curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);
new_conn((char *)"http://us.download.nvidia.com/XFree86/Linux-x86_64/331.79/NVIDIA-Linux-x86_64-331.79.run", &g); /* add a URL */
/* enter io_service run loop */
io_service.run();
curl_multi_cleanup(g.multi);
fprintf(MSG_OUT, "\ndone.\n");
return 0;
}
i see there is no place calling the curl function curl_multi_perform()
how does the tasks get started at the very begining?
I see there is no place calling the curl function curl_multi_perform()
This is because this sample code uses an alternative API called curl_multi_socket_action:
curl_multi_socket_action is then used instead of curl_multi_perform.
(see the MULTI_SOCKET section of the official documentation for more details)
how does the tasks get started at the very begining?
The magic occurs thanks to the CURLMOPT_TIMERFUNCTION option, curl_multi_add_handle function and corresponding timer logic.
If you refer to the static void new_conn(char *url, GlobalInfo *g ) function you can see that:
static void new_conn(char *url, GlobalInfo *g )
{
/* ... */
rc = curl_multi_add_handle(g->multi, conn->easy);
mcode_or_die("new_conn: curl_multi_add_handle", rc);
/* note that the add_handle() will set a time-out to trigger very soon so
that the necessary socket_action() call will be called by this app */
}
So in practice everything starts by calling new_conn(...) which in turn will trigger multi_timer_cb which then calls timer_cb.
And timer_cb performs the curl_multi_socket_action.

Visual Studio 2012 GLFW 3.x Error Message

Long Story short, OpenGL beginner/dabbler, Using GLFW for self study purpose.
I downloaded GLFW precompiled binaries from here
and I followed this tutorial (I know its for VS2010 specific but still)
I have read numerous questions on linker errors for VS2012 + GLFW 3.x set up.
None of them solved my problem.
Here is what I have in my code so far.
#define GLFW_DLL
#include <glfw3.h>
#pragma comment(lib,"glfw3.lib")
#pragma comment(lib,"glfw3dll.lib")
#pragma comment(lib,"opengl32.lib")
int main(int argc,char** argv)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
Here is what I have in my
VC include directory.
VC lib directory
VC linker input options
System32 DLL
Compilation is successful. However, I get
Why, what is wrong with this set up?
UPDATE::
I tried placing all the files (dlls, lib and headers) in the project folder, still no results,
I still get the same error message.
The easiest solution would be to use the static library rather than the dll, thus removing the need for the dll.
To do this you need to remove the define for GLFW_DLL so you file reads:
#include <glfw3.h>
main() // code follows
And you need to remove the glfw3dll.lib from the additional dependencies but leave glfw3.lib and opengl32.lib.

how to fix unsatisfiedLinkError when generating dll for JNI in windows platform using g++

I'm new to native programming. I've been trying to fix the unsatisfiedLinkError past 8-9 hours but got no result. After a lot of googling and stackoverflowing, I got sick of fixing it, I'm posting my problem here. Somebody please please help me.
I'm using g++ compiler in windows 32bit environment.
Here are the files that I've created:
Demo.java
class Demo
{
// Declaration of the native method
public native int methodOfC(int arg1);
/*The native keyword tells the compiler that the implementation of this method is in a native language*/
/*Loading the library containing the implementation of the native method*/
static
{
System.out.println("Control is in Java.......going to call a C program......\n");
System.loadLibrary("try");
System.out.println("Congr8s no prob in CallApi.....\n");
}
public static void main(String[] args)
{
//invoking the native method
int sendToC,getFrmC;
if(args.length!=0) sendToC=Integer.parseInt(args[0]);
else sendToC=999;
Demo ob1=new Demo();
getFrmC=ob1.methodOfC(sendToC);
System.out.println("This is in Java......\n Got "+ getFrmC +" in return from C.");
}//end main
}//end Demo
Demo.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Demo */
#ifndef _Included_Demo
#define _Included_Demo
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Demo
* Method: methodOfC
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Demo_methodOfC
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
DemoImp.c
#include <jni.h>
#include "Demo.h"
#include <stdio.h>
//definition of methodOfC()
JNIEXPORT int JNICALL Java_Demo_methodOfC(JNIEnv* exeenv, jobject javaobj, int getFrmJava)
{
printf("This is in the C program\n Got %d from java",getFrmJava);
printf("\n.......Exiting frm C\n");
return getFrmJava+1;
}
Here is how I compiled and run my prog.: screenshot here
C:\native>javac Demo.java
C:\native>javah -jni Demo
C:\native>g++ -c -l"C:\Java\jdk1.6.0_26\include" -l"C:\Java\jdk1.6.0_26\include\win32" DemoImp.c
C:\native>g++ -shared DemoImp.o -o try.dll
C:\native>java Demo 1234
Control is in Java.......going to call a C program......
Congr8s no prob in CallApi.....
Exception in thread "main" java.lang.UnsatisfiedLinkError: Demo.methodOfC(I)I
at Demo.methodOfC(Native Method)
at Demo.main(Demo.java:23)
C:\native>
I've already added "C:\native" in my system path variable.
I've uploaded all my files in mediafire. Here's the link native.zip
If possible please tell me how can I make 64bit version of dll. Thanks in advance.
You have missed out the package name in the DemoImp.c file.
The naming convention for C function is Java_{package_and_classname}_{function_name}(JNI arguments). The dot in package name shall be replaced by underscore.

How does COM select how to marshal an interface?

As I get it there're three ways to implement marshalling in COM:
typelib marshalling
proxy/stub marshalling
implementing IMarshal by the object
now how does the component consumer (user) choose which one will be used? Does it decide on its own and use the preferred way or does it call some built-in function and it solves the problem for it?
I currently experience the following: my component implements a custom interface ICustomInterface that is also implemented by a component from another company. My component doesn't have a typelib and doesn't implement IMarshal. The system registry contains the HKCR\Interface{uuidof(ICustomInterface)}\ProxyStubClsid32 key with a GUID of the proxy/stub that can be traced to a library provided by that other company.
Now when my component consumer initializes my component it calls QueryInterface() requesting IMarshal from my component and when returned E_NOINTERFACE it just does nothing. Why is this - why doesn't proxy/stub library from the other company kick in?
The COM runtime will use typelib (oleautomation) marshalling if you mark your interface as using the standard marshaler by adding its CLSID {00020424-0000-0000-C000-000000000046} under HKCR\Interfaces\{iid}\ProxyStubClsid (where {iid} is the GUID of your interface). You'll need to have a typelibrary registered too, in order for the runtime to extract the parameter information, and you can only use a certain subset of types. There's some more (old) information here and here.
If you want to use a custom proxy/stub, as generated by the MIDL compiler from your IDL, then you'll need to change the interface registry entry to be the CLSID of that proxy object instead. This enables you to use a wider range of types, e.g. "raw" arrays.
If you support IMarshal then that's what'll be used in preference to either of these mechanisms. This means you can change your object to aggregate the free-threaded marshaler (using its implementation of IMarshal) without having to change anything in the registry. This will avoid any proxies being created.
Hope this helps.
I am a bit rusty at this, but do you have a function named blindquery in your project ? (its usually declared by the wizard if you created a C++ ATL project). Breakpoint inside the function. The function is generated by the wizard often has problems with queryinterface returning E_NOINTERFACE due to buggy code.
edit (found sample code) from my old project _blindquery
class ATL_NO_VTABLE CChildEvents :
public CComObjectRootEx <CComSingleThreadModel>,
public CComCoClass<CChildEvents, &CLSID_ChildEvents>,
public IDispatchImpl<IChildEvents, &IID_IChildEvents, &LIBID_XXX>
{
public:
CChildEvents(void) :
m_pItfMgr(0)
{
}
/* called from internalQI to tear off a new blind interface */
static HRESULT WINAPI _BlindQuery(void *pvThis, REFIID riid, void **ppv, DWORD dw);
DECLARE_REGISTRY_RESOURCEID(IDR_CHILDEVENTS)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CChildEvents)
COM_INTERFACE_ENTRY(IChildEvents)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY_FUNC_BLIND(0, _BlindQuery)
END_COM_MAP()
};
HRESULT WINAPI CChildEvents::_BlindQuery(void *pvThis, REFIID riid, void **ppv, DWORD /* dw */ )
{
HRESULT hr = E_NOINTERFACE;
USES_CONVERSION;
try
{
if(pvThis == NULL)
{
ATLASSERT(FALSE);
}
else
{
/*
* cast the pvThis pointer to the actual class £
* so we can use it here £
* reinterpret_cast should be safe since we're calling ourself
*/
CChildEvents *pThis = reinterpret_cast < CChildEvents * > (pvThis);
if(pThis == NULL)
{
ATLASSERT(FALSE);
}
else
{
/* check to see if it matches on of our children's DIID */
if(memcmp(&riid,&l_someotherguid,sizeof(GUID)) == 0) {
/* if so cast to a IDispatch -- the standard for event interfaces */
*ppv = reinterpret_cast < IDispatch * > (pvThis);
/* addref */
pThis->AddRef();
/* reply */
hr = S_OK;
}
}
}
}
catch(...)
{
ATLASSERT(FALSE);
}
/* must not be in our map - tell them to GO FISH */
return(hr);
}

Resources