View previous topic :: View next topic |
Author |
Message |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Thu Jun 26, 2008 1:19 am Post subject: C# & C dll help |
|
|
ok, i have a dll i made in C *yes its basic* and i have a couple questions.
1. Can a program in C# use variables from the C dll? Like, example, use MessageBox.Show in C# to show a variables value from the C dll?
And secondly. I know this is really nooby, but i have having problems with showing a message box in the dll. So when you call its function, it will get the mouse coordinates and display them in a message box. Here is my code:
Code: | #include <stdio.h>
#include <windows.h>
extern "C" {
void __declspec (dllexport) MouseCoords() {
POINT coords;
float x = 0;
float y = 0;
GetCursorPos(&coords);
x = coords.x;
y = coords.y;
MessageBox(
NULL,
L"X Coordinates: "
strcat(coords.x));
}
}
BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID) {
return TRUE;
}
|
EDIT: and i get these errors: Quote: | Warning 1 warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data c:\documents and settings\tyler\desktop\mouse.dll\mouse.dll\mouse.dll.cpp 18
|
i messed with the code, can't seem to fix it.
yea, i know i am a complete noob with messing with strings (using strcat), so don't flame me, i already did it for you guys -_-
Thanks for the help.  |
|
Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Thu Jun 26, 2008 3:17 am Post subject: |
|
|
Warning != Error
and
MessageBox(
NULL,
L"X Coordinates: "
strcat(coords.x));
}
wheres your comma?
besides, strcat doesn't take 1 parameter. |
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Thu Jun 26, 2008 4:15 am Post subject: |
|
|
Make a function that returns your variable and import it.
And can I ask why did you declare "float x,y" if you never used them? |
|
Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Thu Jun 26, 2008 1:09 pm Post subject: |
|
|
Symbol wrote: | Make a function that returns your variable and import it.
And can I ask why did you declare "float x,y" if you never used them? |
because i am going to use them. I will use them once i actually figure out how to add them to the end of the message box  |
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Thu Jun 26, 2008 1:19 pm Post subject: |
|
|
Why not just using "coords" instead? |
|
Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Thu Jun 26, 2008 1:43 pm Post subject: |
|
|
Symbol wrote: | Why not just using "coords" instead? |
ok, fine.
But eitherway, i just want to know how to use strcat with a message box. So i can show the value of a variable. This is what i mean (in C#)
Code: | MessageBox.Show("My age is: " + age); |
basically just that in C++... |
|
Back to top |
|
 |
the_undead Expert Cheater
Reputation: 1
Joined: 12 Nov 2006 Posts: 235 Location: Johannesburg, South Africa
|
Posted: Thu Jun 26, 2008 2:20 pm Post subject: |
|
|
strcpy(variable, "My age is: ");
strcat(variable, age); _________________
|
|
Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Jun 26, 2008 5:35 pm Post subject: |
|
|
Overload wrote: | Symbol wrote: | Why not just using "coords" instead? |
ok, fine.
But eitherway, i just want to know how to use strcat with a message box. So i can show the value of a variable. This is what i mean (in C#)
Code: | MessageBox.Show("My age is: " + age); |
basically just that in C++... |
Thats VC++. Native C++ is MessageBox(hwnd, "Message", "Title", MB_OK) _________________
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Thu Jun 26, 2008 6:20 pm Post subject: |
|
|
Code: | wsprintf(buf, TEXT("My age is: %d"), age);
MessageBox(0, buf, TEXT("Age!"), 0); |
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jun 26, 2008 6:49 pm Post subject: |
|
|
POINT expects long values, not floats. |
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Thu Jun 26, 2008 8:10 pm Post subject: |
|
|
Just a suggestion from MSDN about LocalAlloc:
Quote: | Note The local functions are slower than other memory management functions and do not provide as many features. Therefore, new applications should use the heap functions. |
_________________
- Retired. |
|
Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Fri Jun 27, 2008 12:49 am Post subject: |
|
|
Flyte wrote: | Code: | wsprintf(buf, TEXT("My age is: %d"), age);
MessageBox(0, buf, TEXT("Age!"), 0); |
|
so for "buf", do i need to allocate mem? like: (char*) malloc(sizeof(buf));
Is that right? |
|
Back to top |
|
 |
|