|
To use C++ functions you need to do some research into P/Invoke.
Here's how to declare the functions you need in C#:
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplicationTest
{
internal static class NativeMethods
{
[DllImport("User32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
}
}
Usage example:
using System;
using System.Text;
namespace ConsoleApplicationTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to get text");
Console.ReadKey();
IntPtr handle = NativeMethods.GetForegroundWindow();
if (handle != IntPtr.Zero)
{
StringBuilder builder = new StringBuilder(255);
NativeMethods.GetWindowText(handle, builder, builder.Capacity);
Console.WriteLine(builder.ToString());
}
Console.ReadKey();
}
}
}
I have used a hardcoded max length of 255. You can use GetWindowText[^] to get the length of the text before getting the text so you won;t be wasting memory with your string builder or risk truncating if it's longer than you expect.
I'll leave implementing that (which is simple) as an exercise for you.
modified 18-Jun-12 17:55pm.
|
|
|
|
|
1. I have a binary c++ exe. (Proj1)
2. This exe launches another exe (a c# one).(proj2)
3.I have the source code for proj2.
4. When Proj1 calls Proj2 (click of a button), I want to step into the c# code of proj2.
5. I added a Debugger.Break() as the first line in proj2 c# code.
5. I started proj1 running.
6. FRom Proj2 Debug menu, i tried "Attach to Process" the running process proj1.exe.
It attached.
7. I tried to put a breakpoint on Debugger.Break() line. VS 2008 said breakpoint will not be hit , no executable code is associated with this line.
8. I clicked the button in proj1.exe which launches the c# project (proj2).
9. The gui of proj2 came up but did not step into the source code at all.
Evidently I'm doing something wrong.
My goal is to step into the C# source code of proj2 when the binary exe proj1, launches proj2.
thanks,
sb
|
|
|
|
|
Make sure you're building proj2 in Debug, not Release (because I'm pretty sure debugger stuff is stripped out in Release builds).
|
|
|
|
|
Thanks!
It's definitely built in debug mode.
sb
|
|
|
|
|
bonosa wrote: 6. FRom Proj2 Debug menu, i tried "Attach to Process" the running process proj1.exe
That's the reason: you have to attach to proj2.exe.
|
|
|
|
|
From proj2 source code in VS 2008 attach to proj2.exe after starting proj2.exe from proj1.exe? I did that and it did not step into the code. In order to attach proj2 src code from VS2008, proj2.exe has to already be running. It seems circular?
thanks,
sb
|
|
|
|
|
It's not circular. If you want to debug proj2.exe you have to attach the debugger to it. It'll step into the code, but proj2 might be at an idle state when you attach the debugger, so you may have to pause the execution after the debugger attaches. At that point, execution may, or may NOT, be inside your code but inside system code.
If you set a breakpoint in the proj2.exe code and the execution has already gone past, the code won't stop until the breakpoint is hit again or execution ends.
|
|
|
|
|
I am using the following:
Mycontrol.DisplayFormat = "Total: {0}";
It displays the number as it so if it is 1.250 it will show 1.25
How can i force format to 3 decimal points?
|
|
|
|
|
Try:
Mycontrol.DisplayFormat = "Total: {0:F3}";
should give you data till 3 places.
C: Displays numeric values in currency format.
D: Displays numeric values in decimal format.
E: Displays numeric values in scientific (exponential) format.
F: Displays numeric values in fixed format.
G: Displays numeric values in general format.
N: Displays numeric values in number format.
X: Displays numeric values in hexadecimal format.
|
|
|
|
|
Thanks alot
|
|
|
|
|
I use Sql Reporting Services to create the report for an application.The reports are loaded in a web page using the ReportViewer.
My need is to be able to set in advance the Number of copies for a specific report.
I dont want to rely on the user to change the number of copies every time the report is produced, so i want the print dialog box of the Report Viewer ActiveX control to display Number of Copies = 4
|
|
|
|
|
Ok here is the whole code and the problem is right down the bottom with the myDice which I have underlined. Ok I deleted most of the code apart from where the error is
Error.... The name 'myDice' does not exist in the current context
Everything else works fine just not this part!
public int AddUpDice(int DieNumber, int[] Dice)
{
int Sum = 0;
for (int i = 0; i < 5; i++)
{
if (myDice[i].RollNumber == DieNumber)
{
Sum += DieNumber;
}
}
return Sum;
}
}
}
|
|
|
|
|
Rather than dumping the entire code you need to provide the exact error messages produced by the compiler.
[edit]
A quick run of the IDE shows that myDice is declared in the Form1 class and you are trying to access it from the CalculateScore class. However this is not possible without qualifying the name. As I said in answer to a number of your other messages, you should spend some time studying the basics of C#.
[/edit]
|
|
|
|
|
I did state the actual error minus the line number and col number that the compiler mentioned
|
|
|
|
|
Yes I spotted that after I checked the code, and explained what the error was.
|
|
|
|
|
It's in a different class...
CalculateScore is a class within Form1 class - it can't access Form1 objects!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi,
I am reading inbox sms messages from gsm mobile
some messages are being received by following format. Please let me know, how may I convert this into text / string to read easily?
050003B60201AE65F6F8DD2E83E86F50D5FC769743206919CECE83EE693A1A146BCD40F437685E17CFC7F2B4B80CA2A3CBA079596E4F8FCBA0B719549583C6E8777A5C063DA5207919CECE83EE693A1A749A56852750DA0CCABFEBA07B7A8E06D1DFA0795D3C1FCBD3E23288FE0685D96CD0DB0CA2A3CBED9022D6AA52EBEEF21C040049E72E506C450DE35F
Thank you
(Riaz)
|
|
|
|
|
I do not know the structure of SMS messages, but I'm sure Google can find it for you. However, the above looks like hexadecimal so you just need to convert it to normal bytes.
|
|
|
|
|
I wonder what "normal bytes" are, they all look the same to me...
|
|
|
|
|
I changed it from "characters" as that seemed wrong; how would you describe it?
|
|
|
|
|
I'd say it looks like some kind of encoding; half of the hex values shown are above 0x80, so it sure isn't just ASCII characters. Our friend Google would know, as you said.
|
|
|
|
|
I meant rather "convert to ???". I know it's just a HEX representation of some message, and I also know that SMS messages contain lots of odd bits of information.
|
|
|
|
|
Hi can anyone tell me why the myDice which is the underlined part is giving me thie following error please.
name 'myDice' does not exist in the current context
I have up the top of the coding the following so not sure why it is not picking up this particular myDice.
int[] Dice = new int[] { 0, 0, 0, 0, 0, };
int[] myDice = new int[] { 0, 0, 0, 0, 0 };
public int AddUpDice( int DieNumber, int[] Dice )
{
int Sum = 0;
for (int i = 0; i < 5; i++)
{
if (myDice[i].RollNumber == DieNumber)
{
Sum += DieNumber;
}
}
return Sum;
}
|
|
|
|
|
|
how many people will downvote me...i understand this may not be the issue..
|
|
|
|