As documented in http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx, SendMessage() (and that implies SendMessageW()) is defined in user32.lib. This library isn't referenced by default from a CLR project. Adding the library to the additional dependencies on the linker input property page should fix the issue.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Trying to #import "user32.lib" gives the following error:
1>c:\users\fluidz\documents\everything\visual c++ projects\backup of vc++ version\minecraft keybot\minecraft keybot\MCKB.h(6): error C2812: #import is not supported with /clrure and /clr:safe
I have Googled around but I don't know how to swap back to normal CLR.
When I upgrade my project to a Visual Studio one, view the tool in the IDE. I get an error for importing <sal.h>. So basically, it doesn't work on a VC++ project, does on a Visual Studio, however, on the Visual Studio project <sal.h> is missing or non-existent.
Sal error: 1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h(68): fatal error C1083: Cannot open include file: 'sal.h': No such file or directory
Trying to #import "user32.lib" gives the following error:
You should read anything about #import directive. As long as user32.lib is neither a COM server nor type library, you cannot import it. Instead, it appears to be a plain WinAPI import library which should be correspondingly added to your project.
Originally Posted by Eri523
Adding the library to the additional dependencies on the linker input property page should fix the issue.
It's project settings.
Last edited by Igor Vartanov; January 18th, 2012 at 12:39 AM.
Trying to #import "user32.lib" gives the following error:
[...]
As Igor already confirmed, #import is the wrong directive here. The right one, if you don't want to simply add the library on the property page mentioned, is this:
Code:
#pragma comment(lib, "user32.lib")
I have Googled around but I don't know how to swap back to normal CLR.
This option is on the General property page (for the project) and on C/C++ -> General for both the project and individual source files.
[...] I get an error for importing <sal.h>. So basically, it doesn't work on a VC++ project, does on a Visual Studio, however, on the Visual Studio project <sal.h> is missing or non-existent.
Sal error: 1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h(68): fatal error C1083: Cannot open include file: 'sal.h': No such file or directory
I have Visual Studio 10, not 11, but I do have that file, in the same directory as crtdefs.h. Perhaps there's something wrong with your installation? BTW, headers aren't imported either, they're included.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
I do, however, have another. The generic SendMessage(hwnd,WM_CHAR,'a',0); from 'normal' C++ isn't working. Any ideas?
You did include Windows.h or at least Winuser.h, didn't you? From what you told me, I can't really tell you more than that shot in the dark. How did you try to use it and how did it fail?
In the meantime, as a rough outline how calling native functions like that works, following is a C++/CLI module that, among other things, encapsulates the Win32 PostMessage() which, as you probaly know, is quite similar. The module is taken from the demo project attached to http://www.codeguru.com/forum/showthread.php?p=2047542. First the header file:
Code:
// WndMessageHolder.h
#pragma once
#include <Windows.h>
namespace BringUpTest
{
using namespace System;
using namespace System::Windows::Forms;
public ref class WndMessageHolder
{
public:
static WndMessageHolder ^GetInstance();
static Int32 GetLastError_();
initonly int WM_BRINGUP;
initonly int WM_MESSAGEECHO_ADVERTISE;
initonly int WM_MESSAGEECHO_ADVERTISEMENTRESPONSE;
static bool PostMessage_(IWin32Window ^wnd_, int msg_, IntPtr wparam_, IntPtr lparam_);
static bool PostMessage_(IntPtr ipHwnd_, int msg_, IntPtr wparam_, IntPtr lparam_);
static bool BringWindowToTop_(IWin32Window ^wnd_);
static bool BringWindowToTop_(IntPtr ipHwnd_);
protected:
WndMessageHolder();
private:
static WndMessageHolder ^s_wmhInstance = nullptr;
};
}
Of course it would have been possible to directly call the native functions, but I usually prefer to encapsulate stuff like that rather than scattering it all around the entire app.
Last edited by Eri523; January 21st, 2012 at 10:35 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
I tried to use SendMessage with the window in focus and out of focus immediately before another SendMessage which changes the windows title. The second one works, however, the first shows no sign of working at all.
I'm afraid that's still too few information. What is "the window in focus and out of focus"?
Originally Posted by Fluidz
The second one works, however, the first shows no sign of working at all.
Is that meant to mean you're calling SendMessage() twice in succession with identical parameters, and only the second one of those calls results in any observable effect?
The bottom line clearly is: Please post the concrete code involved, best accompanied by a detailed descriptgion of your overall scenario, as is seems to involve some "outside" app in some way.
Perhaps this is a general issue regarding inter-process interaction rather than one specific to C++/CLI or even .NET.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Please post the code in a new post, otherwise I won't get notified when yourf update comes in. (And others aren't able to tell there's something new from the thread listing either.)
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Bookmarks