|
Hi,
How would I go about using an unmanaged DLL in C# ? I have imported some functions using the [DllImports("mydll.dll")] directive which appears to work fine with functions that don't have inputs. But how would I for example use a function that takes the following params:
<br />
[Dllimport(@"mydll.dll")]<br />
public static extern bool Initialize( void * pInitStruct );<br />
The struct I need to use takes the form:
<br />
typedef struct tagInitStruct {<br />
long mS;<br />
long mE;<br />
const char* mAN;<br />
const char* mCAN;<br />
const char* mVI;<br />
const char* mPC;<br />
const char* mRS;<br />
} InitStruct , *InitStructPtr;<br />
How would I recreate that struct in C# and pass it to the DLL function?
I am new to C# BTW.
Thanks in advance.
|
|
|
|
|
This question should be in the C# forum.
Research PInvoke. A good resource pinvoke.net[^]
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
I am trying to convert a VB .NET application into C++ .NET, I am struggling with this task and would like some help. One of the main problems I have is with taking methods from a DLL file. Could you tell me what could I would have to enter into Form1.h to change declarations like this
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _<br />
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _<br />
ByVal cbVer As Integer) As Boolean
into C++ code. I am not sure at all as to how to include dll files and their methods in a C++ application.
I am also having problems with the following method
capGetDriverDescriptionA(x, strName, 100, strVer, 100)
This method
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
belongs to the user32 dll file, but I am not sure as to how to link and import it.
Any help would be appreciated. If possible, please point me in the direction of some tutorials to help. I am a programmer who hasn't touched C++ in about a year, the last IDE I used was Visual C++ 6.0, so you can tell I need help.
|
|
|
|
|
Cantona2k wrote: I am trying to convert a VB .NET application into C++ .NET
Do you mean Managed C++ (VS 2002, 2003), C++/CLI (VS 2005) or even native C++?
Cantona2k wrote: Could you tell me what could I would have to enter into Form1.h to change declarations like this
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
into C++ code.
Just include Vfw.h, link to Vfw32.lib, and call it directly as described here[^]
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Managed C++ in VS .NET 2003
|
|
|
|
|
|
Hello everyone
I need an algorythm to save paths to every leaf in a binary search tree. I'm saving the path in a 2D array (one field for name of the leaf, the other for steps in the tree - 1,0,2).
Anyone has an example of such algorytm, or can tell me how to work on it. I'm a beginner and i dont know much about C++ or programming in general.
Help me please.
|
|
|
|
|
Dear Sir,
I am assigned to draw ( with GLUT ) line chart and Bar chart for ( say = 5 ) inputs. I checked my books and on net , but could not find any helpful coding.
Therefore I uesd fundamenta method to get to a solution. I used six line ( Bresenham algo ) segments to define Two major axes amd foue head - to - tail line ( edges )segments
to define five ( vertices ) Points .
For bar chart , I have drawn five rectangled of a small width and ordinates to define the height ( parameter ).
The result just fulfills ther intent , but is too crude , messy and unpleasant to look at. No parameters or markings .
My query is that ....................
is there any function namely < Draw_BarChart> . like we have < Draw_Circle> or < Draw_Line> in the library, or custum -written . At least I could not locate one.
If there exiats such a function < Tool > , please provide me the link , to work upon. I will be futher obliged , if I can get < charts> code in C++ or any other version of C .
Thanks ,
ah.
|
|
|
|
|
how can i perform HTTP GET and POST using C++?
|
|
|
|
|
if it is unmanaged c++, you can use XMLHTTP class and its methods open, send etc in MSXML library.
In .net i guess HTTPWebResponse, HTTPWebRequest are similar. Of course you can send and recieve web urls using these classes, but I am not sure whehter we can specify the request mode as GET/POST.
rgds..milton.
|
|
|
|
|
Mridang Agarwal wrote: ow can i perform HTTP GET and POST using C++?
if Unmanaged,as it sound like! , try http://www.codeproject.com/internet/simplehttpclient.asp
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi all
i am a beginer programmer. so u might have feel bore to read this problem.
i dont know what is the use of extern.
i wrote a file like
int i=10;
then save it as t.h
then i included it in my program as
#include "t.h"
then i got the value of i just by using
printf("%d",i);
it printed the value of i 10
but i thouht that i would have to use the statement
extern int i;
to get the desired output?
if we dont want extern here what is the exact use of extern.
pls help me.
shamnar
|
|
|
|
|
In one .CPP file declare the variable at global space
int ix;
In the file that you want the variable to be used or say stdafx.h that is included in all the other files write:
extern int ix;
The extern keyword confirms to the compiler that "ix" is an int declared in some other .CPP file.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
but without using extern, just by an include statement i got the desired o/p.
why do we go 4 such a complex concept?
shamnar
|
|
|
|
|
Without extern, every translation unit (cpp file) in which you included i gets its own i. That is, each translation unit reserves memory for the variable.
Did you try including thhe file in multiple cpp files? You'll find that the code won't link, you'll get linker errors complaining about multiple symbol redefinitions for i. The reason is the same, each cpp file has a global i, so the linker doesn't know which i to use.
The solution is to define the variable in one cpp file and to declare the variable extern in the header file. This way, all cpp files including the header files will recognize that variable is defined somewhere else.
Does this answer your question?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thank you..........
shamnar
|
|
|
|
|
Hi,
Iam trying to implement a cross-platform encryption system.
i.e, in windows i will encrypt a file and in Linux will try to decrypt it and viceversa. The same encryption algorithm can be used on both platforms.
NET has Cryptography namespace in which all this algo are implemented and API's available. But when we go in to linux , we cannot use this .NET API's. so, some libraries muist be available to implement this algo in both platforms.
I got some info on using OPENSSL libraries which i can use for implementing encryption algo. But some problems is ther when it comes to cross platform.
So, need some guidelines and ideas for this.
Please mail me if u had come across similar situation and help in the same.
Thanks.
Mani
|
|
|
|
|
Can u be more specific abt the problems u faced.
For cross platform code usability,the general practice is to make code in c/c++,STL. Then compile/link it on diffrent platforms which ever is required.
There are lots of free source code available on net which compiles with both Microssoft CL.exe and the unix/linux GCC.
cheers...milton.
|
|
|
|
|
What I need to do is this:
To take a structure (or a class that contains only variables) then convert it somehow to an array of bytes, so i will be able to send it with the Write function of the SerialPort Control.
On the other side of the port i need to do backward process
Can anyone help me with this one?
thanks
|
|
|
|
|
Call createfile to get a valid handle to the port:
hPort = CreateFile(lpszPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL,<br />
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |<br />
FILE_FLAG_OVERLAPPED, NULL);
Then set the device control block with appropriate baude rate and parity bit settings and other settings.
<br />
DCB dcb; <br />
dcb.DCBlength = sizeof( DCB ) ;<br />
GetCommState( ufp, &dcb ) ;<br />
dcb.BaudRate = baud;<br />
SetCommState(ufp, &dcb);
Now you can start writing to the device.
WriteFile(hPort, bfr2write, dwBytestoWrite, &dwBytesWritten, &OVERLAPPEDWrite);
To Readfrom the file:
ClearCommError( hPort, &dwErrorFlags, &ComStat ) ;
dwLength = min( (DWORD) MaxLength, ComStat.cbInQue );
if (dwLength > 0) {<br />
fReadStat = ReadFile( hPort, lpzBlock,
dwLength, &dwLength, &osRead ) ;<br />
if (!fReadStat) {<br />
Err("ReadSPort");<br />
dwLength = 0 ;<br />
ClearCommError( hPort, &dwErrorFlags, &ComStat ) ;<br />
}<br />
}
cheers...milton.
|
|
|
|
|
Thanks,
But in this way I don’t really use the SerialPort Control that .net 2 gave me.
Do u know how to do it with the SerialPort Control?
|
|
|
|
|
|
I am working to upgrade an application to manadeg code which has to use unmanaged DB functions and a large DB created with them.
I have been able to read the records sequentially, and lets say I have read a value of an existing record key field(long) and named it Currtmp, could anyone perhaps give me an opinion on my try (based on an earlier piece of advice by Milton KB)
String ^crpt = Currtmp.ToString();
pin_ptr<const void*=""> tnoptr = static_cast<marshal::stringtohglobalansi(crpt)>.ToPointer();
d:keyfind(..., tnoptr, ...);
In compiling I receive the error
error C2061: syntax error:identifier 'StringToHGlobalAnsi'
When editing the line of pin_ptr ..., the editor gives after the two colons as one alternative this 'StringToHGlobalAnsi',
but in compiling I get the above error. Is this completely wrong thinking.
When I move the mouse focus on the line to the point over the 'StringToHGlobalAnsi' a box appears containing
static System::IntPtr System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(System::String ^s)
copies the contents of managed System.String into unmanaged memory, converting into ANSI format as it copies
so at least the text would indicate that I could be on the right road, but ...
I have also tried several other identifiers instead of 'const void*', with similar results. The native code function needs the identifier (const void*).
Ilkka Pitkänen
|
|
|
|
|
I juz went thru my reply to your previous post.
There I suggested to use __gc char* and it was a .net 1.1 syntax. This might have failed for you if you are using .net 2.0.
But in your new code, you are using pin_ptr . This is not required if you are using StringToHGlobalAnsi . Because StringToHGlobalAnsi will allocate memory in the unmanaged heap and .Net GC can't do anything on this unamaged memory. So you dont have to pin it to prevent from memory relocation.
Try below coed. This works in 2.0 with /clr:pure
long Currtmp = 117;<br />
String ^crpt = Currtmp.ToString();<br />
IntPtr intptr = Marshal::StringToHGlobalAnsi(crpt);<br />
d:keyfind(..., intptr.ToPointer(), ...);<br />
Marshal::FreeHGlobal(intptr);
cheers...milton.
|
|
|
|
|
I have a native c++ class in a native code dll.
I wrapped it with a managed c++ class library in visual studio 2005 by:
1. Creating an instance to the native class in my constructor and deleting the instance in the destructor.
2. Implementing all of it's interface and calling each matching function.
I was able to compile the class library succesfully.
When attempting to use it in a CLR console application I Added a reference to it in the application.
The autocomplete recognizes the classes and recognizes the public functions of the classes.
My problem is that when I compile the program i get the following error:
error C3767: 'XP_Talk::XPMyClass::Init' candidate function(s) not accessible.
Why does this happen? XPMyClass::Init was declared public and is seen in autocomplete as public...
So why do i recieve this error and how do i resolve the problem?
|
|
|
|
|