|
If this is another .NET application, you could use .NET Remoting to communicate across the two AppDomain hosted by each process. Another way - and if the process is a native application - is to P/Invoke FindWindow to find a Window with the given text (assuming the dialog has a unique caption):
[DllImport("user32.dll", CharSet=CharSet.Auto)]
IntPtr FindWindow(string class, string caption);
...
IntPtr hWnd = FindWindow(null, "My Dialog Caption");
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
Dose anybody know where can i download "Server 2003 DDK", and i need to write a program to comunicate and transfer files with a remote computer via modem with this protocols (ZMODEM/XMODEM), can you send me some hint or source code links to help me to start it.
thanks in advance.
|
|
|
|
|
|
Our clients using windows platform, please give me windows based hint.
thanx
|
|
|
|
|
This is the C# forum, not the Windows or Windows DDK forum. Please post to the C/C++ forum or the OS forum, or go to http://msdn.microsoft.com[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
I am trying to import some functions from an open source library(DLL).
//Here is the function definition in C/C++
PJ* pj_init(int argc, char **argv);
//Here is the PJ struct in a .h file
typedef struct PJconsts {
XY (*fwd)(LP, struct PJconsts *);
LP (*inv)(XY, struct PJconsts *);
void (*spc)(LP, struct PJconsts *, struct FACTORS *);
void (*pfree)(struct PJconsts *);
const char *descr;
paralist *params; /* parameter list */
int over; /* over-range flag */
int geoc; /* geocentric latitude flag */
int is_latlong; /* proj=latlong ... not really a projection at all */
int is_geocent; /* proj=geocent ... not really a projection at all */
double
a, /* major axis or radius if es==0 */
e, /* eccentricity */
es, /* e ^ 2 */
ra, /* 1/A */
one_es, /* 1 - e^2 */
rone_es, /* 1/one_es */
lam0, phi0, /* central longitude, latitude */
x0, y0, /* easting and northing */
k0, /* general scaling factor */
to_meter, fr_meter; /* cartesian scaling */
int datum_type; /* PJD_UNKNOWN/3PARAM/7PARAM/GRIDSHIFT/WGS84 */
double datum_params[7];
double from_greenwich; /* prime meridian offset (in radians) */
#ifdef PROJ_PARMS__
PROJ_PARMS__
#endif /* end of optional extensions */
} PJ;
I understand that I need to use DLLImport to import the function and [ StructLayout( LayoutKind.Sequential )] to create a clss representing the struct, but I'm clueless on the first 4 lines in the struct above:
XY (*fwd)(LP, struct PJconsts *);
LP (*inv)(XY, struct PJconsts *);
void (*spc)(LP, struct PJconsts *, struct FACTORS *);
void (*pfree)(struct PJconsts *);
XY and LP are simple structs
typedef struct { double x, y; } XY;
typedef struct { double lam, phi; } LP;
Any ideas?
Thanks,
sam
|
|
|
|
|
The XY and LP structs are easy:
[StructLayout(LayoutKind.Sequential)]
public struct XY
{
public double x;
public double y;
}
[StructLayout(LayoutKind.Sequential)]
public struct LP
{
public double lam;
public double phi;
} If you look at the PJconsts struct, though, it's actually being used as a class (possible in C++). You should instead define this as a class, keeping in mind that anything declared as a class is a reference Type already, so you don't need a pointer to it. If you need to pass a reference to a value type (like struct s, for example), use either the out or ref keyword, depending on whether or not the param is defined as [out] or [in,out] respectively.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Yeah XY and LP are easy, my problem is the PJconsts struct..... which is really the PJ struct, I think the PJconsts is some type of C label, while PJ is the actual name. This thread http://forums.devshed.com/archive/42/2003/9/1/80923 talks a bit about it...
and what is the deal with the first 4 lines of the struct.....
|
|
|
|
|
They're method declarations, which is why I was saying that this could be better suited for a class. This was a way in C to declare class-like entities.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
XY (*fwd)(LP, struct PJconsts *);
LP (*inv)(XY, struct PJconsts *);
void (*spc)(LP, struct PJconsts *, struct FACTORS *);
void (*pfree)(struct PJconsts *);
Obviously, we dealing with function pointers here, aka CALLBACK. You can safely use static delegate instances for this. I'm not sure about returning those structs, marshalling could give you either a pointer or a value, you will just have to try.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I'm still having problems with the marshalling
I get an exception "Can not marshal field param of type ProjWrapper.PJ: The type definition of this field has no layout information."
I have tagged it with Layout.Sequential
public delegate XY fwd(LP lp, PJ pj); <br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public class PJ<br />
{<br />
fwd fwdcallback;<br />
}
Could the problem be in the return Marshal of the PJ class, or am I messing up the callback definitions still
Thank you very much for your help....
-Sam
|
|
|
|
|
sammyh wrote:
fwd fwdcallback;
//etc
Somewhere after the //etc is the error
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
alright... progress, seems to be working
The last 2 hurdles
First I was doing this
[StructLayout(LayoutKind.Sequential)]<br />
public class paralist <br />
{<br />
paralist next;<br />
char used;<br />
char param; <br />
}
when it likes this better
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe class paralist <br />
{<br />
paralist *next;<br />
char used;<br />
char param; <br />
}
Second, I had to replace
fwd fwdcallback;
with
int fwdcallback;
Thanks again.
|
|
|
|
|
i downloaded and installed the directx sdk. how do i use it in my project? the microsoft.directx namespace isn't available and i can't figure out to add a refernce to it.
what am i missing?
thanks
|
|
|
|
|
You should start by opening some samples and playing with them...
If everything is installed right, you should just be able to click Project->Add Reference, and they should be under the .NET tab.
The dlls are in C:\WINDOWS\Microsoft.NET\Managed DirectX if you need to do a direct reference
|
|
|
|
|
Did you install the Summer 2003 update or an older one? They all install a little differently.
For starters, the Microsoft.DirectX namespaces aren't available until the assembly that declares them is referenced. To reference these, first try installing the managed extensions (one one of the installations, these weren't installed while installing the SDK - don't remember which, though) from DXSDKDIR\Developer Runtime\Managed DirectX then from either the Debug or Retail directory. Start VS.NET and you should see the DirectX managed assemblies in the list now.
If you don't, find the location of the installed libraries (like %WINDIR%\Microsoft.NET\Managed DirectX\v9.00.1126) and add the path to the HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders registry key using regedit.exe.
I've installed three or four different versions / updates since the first managed assemblies were released over a short period of time to, unfortunately, I can't remember how they all behaved during installation. The directions above should do the trick, though.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
i installed the summer 2003 update. i see the dlls in C:\WINNT\Microsoft.NET\Managed DirectX\v9.00.1126. i followed your directions, but i'm not sure if it worked. when i try and add a reference, i don't see any directx dll's on the .net tab. on the com tab, i see things like direct 1.0 type library, directx 8 for visual basic type library, among others. do i use one of these? i tried a few of them, but nothing seemed to work.
thanks for your help.
|
|
|
|
|
Did you start/restart VS.NET? Once you add that registry key like the others you should've seen in there, VS.NET won't pick them up again if you've already opened the Add Reference dialog once before. You have to restart for the change to take effect.
I wouldn't recommend using the COM interface. Developers were doing that before DirectX 9 introduced the managed assemblies and it was always a pain. There are several articles here on CP that dealt with those cases (or encapsulated the native functions).
If you're still having trouble after trying all this, go to http://msdn.microsoft.com/directx[^] and check out any support articles that seem relevant. This should all work, though. I had to do it once after installing one of the versions (DirectX 9.0, then a, then b, then Summer 2003 update) and everything has worked fine after that. Now if I could only find a good DirectX development book because I have a passive interest in games development (just curiousity, mostly).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
.NET Game Programming with DirectX 9, Alexandre Lobao. APress.
Managed DirectX 9 Graphics and Game Programming, SAMS.
Lobao's book was "panned" by lots of reviewers, and i have to admit i didn't build the projects (actually i hardly parse vb) but to me it seems like a great overview of how stuff is actually written (there are lots of technical books on 3d, kinematics etc for further reading if you get interested).
|
|
|
|
|
In C++, I can do this (this is ugly and simplified):
void Foo()
{
CMyClass cMyClass;
Bar( (void*) &cMyClass );
}
void Bar( void* pData )
{
CMyClass* pMyClass = static_cast<CMyClass*>(pData);
}
In C#, how can I convert an object (class) to an array of bytes, send that to someone else (e.g., with sockets), and then recreate that object with that array of bytes. Is using BinaryFormatter on a MemoryStream what I need?
To further complicate things, what if I don't know the class type, but I KNOW that it is derived from a particular base class? E.g., I know it's a CAnimal, but I don't know if it is a CElephant or a CDog. How can I find out?
Thanks
|
|
|
|
|
public void Foo()
{
MyClass o = new MyClass();
Bar(o);
}
public void Bar(object data)
{
MyClass o = (MyClass)data;
} In .NET, everything deriving from Object (except for ValueType and its derivatives like the intrinsics, enums, and structs) are reference types already (well, the instances of the classes deriving from Object ) and everything derives from Object . So, for anything declared as a class , it's instance is a reference type.
As far as sending objects to another context, .NET Remoting is the de facto technology in .NET to do this. In the base class library, you can choose from the BinaryFormatter or the SoapFormatter (binary would obviously be faster but not easily interoperable with other technologies like J2EE). Serialization is required when crossing different contexts (even within the same AppDomain ) and Remoting is recommend (required in some cases) when crossing AppDomain s (even within the same process, which it's recommended you use a TcpChannel for communication). See Accessing Objects in Other Application Domains[^] on MSDN for more information.
For a good intro and intermediate book on .NET Remoting, see "Microsoft .NET Remoting"[^] by McLean, Naftel, and Williams.
As far as dealing with base classes, this is easily handled by an object-oriented framework like .NET and Java. For example, you could declare a parameter as even an Object , or the base class for your objects. The Common Type System (CTS) will ensure that when you're compiling any direct calls to that method use a parameter that is indeed a derivative class of the parameter Type. If you use abstract and virtual methods in your base class and override those in your derivative classes, those methods will be called instead of their base class's methods (you can use the base keyword to call the base class's methods inside the overridden methods). This is polymorphism. See the Common Type System[^] for some more information.
For example, the Object class has a virtual ToString method that, by default, returns the object's Type. If a class overrides this, it can return something else. An Enum returns the enum member name (or a comma-delimited list of names for enums that are attributed with the FlagsAttribute ). Many other classes override this method as well.
Also, the Object.GetType method is not virtual and will return the actual Type of the object, regardless of whether the variable is declared as an object or another base class:
object o = new Button();
Console.WriteLine(o.GetType()); Would print:
System.Windows.Forms.Button So, you can use the GetType to see if you're dealing with an Elephant or a Dog (BTW, the hungarian notation is not recommended for use in .NET languages - just thing of what the base class library uses for examples of how to name your classes, etc., or see the Naming Guidelines[^]).
The C# language makes this easier with several keywords you can use, such as is and as :
public void Feed(Animal a)
{
if (a is Elephant) Buy(Food.Peanuts);
if (a is Dog) Buy(Food.Peanuts);
} Of course, the above example is better suited for polymorphism by using the abstract keyword and overriding in the derivate classes to feed the animal what's necessary, but it's just an example.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks, that helps a lot. I understand polymorphism, I just wasn't sure about how to achieve this in C# syntax.
|
|
|
|
|
Good! I hope I didn't offend you talking about polymorphism. I just usually make assumptions if nothing is indicated in a post to avoid constant reposting to provide more information. If nothing else, someone googling for answers may find our little thread useful (which is why I dislike forum members taking questions directly to me via email - it doesn't benefit the community).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
Good! I hope I didn't offend you talking about polymorphism.
None taken. I appreciate your quick and detailed answer.
|
|
|
|
|