Darc Posted November 6, 2003 Posted November 6, 2003 I had a simple mathequation that I thought I might speed up using a Win32 DLL but it's returning a different value than in VB (the one that I hoped for). Here's the code in VB (the one that works) and the code in C++ (which returns a bad value): Dim y As Integer = CInt(arY + (((arHeight - crdHeight) / NumCards) * crdNum)) //C++ VS 2003 return arY + (((arHeight - crdHeight) / NumCards) * crdNum); Quote
Administrators PlausiblyDamp Posted November 6, 2003 Administrators Posted November 6, 2003 what are the data types for arHeight, crdHeight, NumCards and crdNum in both VB and C++? Also in C++ what is the functions return type? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Darc Posted November 6, 2003 Author Posted November 6, 2003 oh, arY, arHeight and crdHeight are integers in both, and NumCards and crdNum are longs in both. The Function returns an integer Quote
Administrators PlausiblyDamp Posted November 6, 2003 Administrators Posted November 6, 2003 What are the differing results? Also you will probably find the difference in speed is going to be minimal at best, it really may not be worth the effort of moving this function to C / C++ Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Darc Posted November 6, 2003 Author Posted November 6, 2003 well the program I use this for does this function about 1 000 times on average per frame. the C++ portion is returning arY, that's it Quote
Administrators PlausiblyDamp Posted November 7, 2003 Administrators Posted November 7, 2003 How are the results differing? Is the C++ one just comming up with a completely wrong number or just returning a number that is slightly off? Could be down to rounding errors in the choice of data types. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
AndreRyan Posted November 8, 2003 Posted November 8, 2003 Try this, grouping everything may help, I'm not a C++ programmer though so I can't be sure //C++ VS 2003 return (arY + (((arHeight - crdHeight) / NumCards) * crdNum)); Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Darc Posted November 8, 2003 Author Posted November 8, 2003 when I call it, it returns JUST the value of arY, nothing else Quote
Darc Posted November 8, 2003 Author Posted November 8, 2003 ok, I changed the Function definition to: short _stdcall SetYPosition(long NumCards, long crdNum, int crdHeight, int arHeight, int arY) //it was: //short _stdcall SetYPosition(int arY, long NumCards, long crdNum, int crdHeight, int arHeight) now its returning the value of crdHeight every time! Quote
Darc Posted November 8, 2003 Author Posted November 8, 2003 got it! longs in C++ are integers in .NET :S working fine now thanx everyone Quote
Recommended Posts