|
Code something like this:
HWND hwndControl = ::GetDlgItem(GetSafeHwnd(), IDC_PICTUREBOX);
ASSERT(hwndControl);
CRect rec;
VERIFY(::GetWindowRect(hwndControl, &rec));
VERIFY(::MapWindowPoints(NULL, GetSafeHwnd(), reinterpret_cast<LPPOINT>(&rec), 2) != 0);
Steve
|
|
|
|
|
I'm trying to pass a pointer to struct between a C++ DLL and a C# app, both of which I'm writing. The code below compiles and runs, but the C++ pointer does not seem to be copied to C#. I've simplified the code for ease of reading. I think I need to use MarshalAs and have tried it out but either I can't get it to compile or doesn't work. Any help that can be offered is greatly appreciated. Thanks!
My C++ DLL has the following declarations:
struct record {
char name[32];
}
__declspec(dllexport) void get_name(record *record_to_get);
void get_name(record *record_to_get)
{
record_to_get = local_unmanaged_record;
}
Here is my C# code:
public class Win32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct record
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string name;
};
[DllImport("my_cpp.dll")]
public static extern void get_name(ref record record_to_get);
}
In another class, I have:
Win32.record test_record = new Win32.record();
get_name(ref test_record);
Console.Writeline("record data = {0}", test_record.name); // Nothing is printed
|
|
|
|
|
I need to catch Windows PowerDown from a process and block it.
This is nicely implemented in MS Outlook 2002 or later (try to power down your computer when MS Outlook is running)
1. How can I catch a Windows PowerDown (or Hibernation) Event without using window (HWND) message queue
2. A way to block or deactivate the PowerDown
Any help will realy help, thank you
|
|
|
|
|
What's the problem with using a window? It need not be visible.
Steve
|
|
|
|
|
we can't use visible HWND window in our app, and invisible window don't behave well
|
|
|
|
|
Invisible window work just fine. Windows use the technique itself, for example COM uses invisible windows in some circumstances. Later versions of Windows also have message-only windows.
Steve
|
|
|
|
|
I tried the way using creating classic HWND window receiving WM_POWERBROADCAST and returning BROADCAST_QUERY_DENY. Problem is - if I create the window and let it invisible, it don't receive any WM_POWEBROADCAST message.
|
|
|
|
|
Hello. I'm trying to load beta versions of my app on a few computers and encountering something I haven't seen before. On most of the computers the app (an executable and 1 dll) loads fine but on 2 machines I get a message saying that the installation was incorrect and the application won't run. I've run depends.exe and received an intimidating list of dependencies. On a sort of educated guess I've also loaded mfc80.dll, msvcr80.dll and msvcrt.dll, but all to no avail. Also, I'm able to load a debug version of the app when the release mode fails, but that's not any kind of long-term solution. If anybody has any suggestions that would be greatly appreciated. Thank you.
|
|
|
|
|
You need to execute vcredist_x86.exe on the target machine. This will install the MFC and C-runtime libraries.
You can download it from here[^]. If you have installed the SP1, check the links at the bottom of the page for the SP1 version.
|
|
|
|
|
I didn't want to reply until I tested it on a client's machine, but it worked perfectly. Thanks a lot!
|
|
|
|
|
How come I can work with int *, but it does not work the same for
Object ptr's
This code works, but just try changing the int to a class object
and NOTHING will work. Note: Object test code is not listed cause it dont work!
I'm trying to learn to work with class pointers, but I can't get anything to work
Thanks - Areal
********************************************* the code
// A simple class for testing pointers
class Object {
int id;
public:
Object() {};
~Object() {};
void setid(int _id) { id = _id;}
int getid() { return this->;id; }
};
int * foo( int * addr);
Object * foo( Object * addr);
int main(int argc, char* argv[])
{
// These are the test subjects
Object o, obj1;
int a;
// end area
// General pointers for both test cases
Object *op;
int *p;
int *swap_addr;
Object *op_swap_addr;
// end area
// just initilize pointers
swap_addr=0;
p=0;
// end area
// Now set int/Object variables for testing
a = 10;
o.setid(999);
// end area
// Pointer assignment for int a
p=&a;
// end area
// Now run the test for the integer variable sending the pointer through foo
cout << "Value of a is ... " << a << endl;
cout << "Value of p is ... " << p << endl;
cout << "Value of *p is ... " <<*p << endl;
swap_addr = foo (p);
cout << "Value of swap_addr comming from foo is ... " << swap_addr << endl;
cout << "Value of *swap_addr comming from foo is ... " <<*swap_addr << endl;
// END FIRST AREA TEST PASSED
return 0;
}
int * foo( int * addr)
{
cout << "Value of addr in foo is ... " << addr << endl;
return addr;
}
// Object
Object * foo( Object * addr)
{
cout << "Value of addr in foo is ... "<< addr << endl;
return addr;
}
|
|
|
|
|
What's not working? Compiler errors? Runtime errors? Errors on what line(s)??
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Areal Person wrote: Object test code is not listed cause it dont work!
Perhaps is more useful if you post the not-working code, since you need to fix it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
The Problem is...
I can't get pointers to work with objects that I define.
If I use an "int" I can do anything I want with pointers, but
if I create an object, it seems that the pointer rules are different.
I don't understand why the pointers do not work the same for both.
-Areal
|
|
|
|
|
Areal Person wrote: it seems that the pointer rules are different
They are the same.
You'll need to show us something that's not working...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am currently using the NDK 2.0 which is working great (NDK uses CSocket).
Here is the problem....
I have a server running on Computer A which resides a couple of miles away. When trying to connect from Computer B, I am unsuccessful.
I use HughesNet (DirecWay) satellite as my way to connect to the internet. On both ends are a local network that the Hughes net modem assigns internal IP addresses (192.xxx.xxx.xxx addresses). I can get the external IP address (using www.checkip.org) no problem.
I can even ping the external IP addresses with no problems (with firewall disabled).
Trying to communicate from Computer A to B or B to A produces an "unable to connect" message.
I have disabled the firewalls and still the same. I can "ping" the server computer no problem, but connecting using NDK (CSocket) is not possible.
Any ideas? Can someone point me to code/articles that may help. What am I missing here? Do I need a special port?
Thanks..
Tim
|
|
|
|
|
Member 260880 wrote: On both ends are a local network that the Hughes net modem assigns internal IP addresses (192.xxx.xxx.xxx addresses)
It is there, on the server (listener) end, that you need to forward packets for the
appropriate port to the machine running the server.
No special port is necessary - any non-reserved, not-in-use port number should work.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Okay this subject is where I am rather green....
If server (listener) is running on the same local network, all works fine (nothing special). Create socket, open on port X and listen (I'm using NDK 2.0).
If I try to connect over the internet to my listening server (uses NDK 2.0 code as server), the connection cannot be made even though I can ping the computer from a far.
So your response about forwarding packets does not make sense.
I'm trying to learn this stuff....
Tim
|
|
|
|
|
You aren't actually pinging the computer from outside the LAN.
You're pinging the public IP address which is the address of the gateway/modem/router.
From there, there's no way an incoming packet can be routed to a specific computer unless
the modem/router is configured to forward packets bound for a specific port to a specific
computer on the LAN.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Your answer does not seem correct... I say that because of the number of "live chat" session that happen when seeking help. For example, Sprint.com, Dell.com, etc. These are not modifying the modem/router.
So it begs the question, how are these programs do it?
I read the NAT article, very good, but I'm still un-certain what to do.
|
|
|
|
|
It's possible I'm not correct, but with the info so far it's the most likely problem.
I'm not familiar with your exact gateway connection - the modem/router/etc that separates
your internal network (with local addresses like 192.168.1.100 for example) from the internet,
where the public IP address is visible from, but there has to be some kind of translation.
If the device only allows one computer connection, then it may just pass all communication directly
to the computer. There could be firewall protection in the device to prevent this.
If multiple computers can be connected to the device, then there HAS to be NAT going on there.
Member 260880 wrote: For example, Sprint.com, Dell.com, etc. These are not modifying the modem/router.
As far as live chat sessions - all the major players have their own servers. Most home routers/modems/gateways
allow outgoing connections by default, so a server outside your network is as easy to connect to as
any HTTP server on the web. For example, Microsoft Live Messenger uses "relay servers" - servers
that allow the two endpoints to connect to them, and they just pass data through. The key is, the endpoints
only need to establish an outbound connection - no inbound connections are necessary to the NAT-protected
computers.
I do live multimedia communication for a living - this is a major issue. I use relay servers as well for clients that
absolutely can't (or won't) allow incoming connections into their LAN.
Mark
*edit* I took a look at HughesNet and their advertised modems - the modems provide NAT, routing, and firewall features - all of which can prevent or allow incoming connections. I'm pretty sure a quick configuration change there will get you connecting
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the info and patience - I'll contact Hughes Net and see how/if I can configure my modem.
|
|
|
|
|
Here's what Hughes.net is saying...
Tim, as I understand you want to remotely access a computer. I would like to inform you that as far, as ports are concerned HughesNet does not block any ports. Tim, I am sorry but we do not have information about the Remote Access where you can remotely access the computer at Business end from HughesNet system. However if you want to remotely access the HughesNet system from the Business end then you would require a static IP. While checking the records I found that you do not have a Static IP. A static IP address allows you to gain access to your computer from the internet. To get the Static IP I would suggest you to contact Billing Department. I am sorry to inform you but HughesNet does not provide technical assistance with Remote Access.
I'm at a lost. As mentioned previously, Sprint/Dell and others allow "chat" with no problems. Maybe the problem is with using CSocket where as Sprint/Dell is using the browser and they use something else? I'm lost...
Thanks..
|
|
|
|
|
For the "others" that allow chat, remember, they're doing that differently - through their servers.
However, you want to run a server behind your modem/router - that requires incoming connections,
which need to get to the computer listening for them.
I googled "HughesNet port forwarding" last night and most hits stated that a static IP was needed.
I'm not sure why, except for the fact that dynamic IP can change making hard for remote nodes to connect,
but it should still work the same if the other end knows what IP you have at the moment.
Regardless, there were a lot of hits saying the static IP was required.
As far as configuring the hardware - that "should" be trivial. Generally there's an HTTP interface to do the
configuration, but I couldn't find any specifics on the HughesNet modems. Google will help there for sure though.
I went through this when I first started communication programming - I'm a programmer, not an IT guy, dammit!
You'll know your network really well when you get it working
Good luck - you can do it!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
This may help explain it a bit...
Network Address Translation[^]
I'm not trying to blow it off with a wiki link but I have to run for a bit and didn't
want to leave you hanging
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|