|
bob16972 wrote: What kind of C based language
If you are doing mixed mode you can still use the C++ formatting libraries.
bob16972 wrote: Last I heard, even Java 1.5 or 5.0 or whatever it is added printf style formatting to their string class.
Have not done any Java in the past couple of years, don't know if I ever will again.
led mike
|
|
|
|
|
just a disclaimer... That wasn't meant toward you. I was gasping aloud so my apologies if that came off as somehow blaming you. When I reread it, it just doesn't sound right so again, my apologies.
|
|
|
|
|
I knew that but thanks for the concern, Also see George Jacksons reply which shows how String.Format uses format specifiers. He picked up my slack.
led mike
|
|
|
|
|
You can do this:
String ^str = String::Format("{0,25}{1,15}{2,15}", str1, str2, str3);
for with the values right-aligned and this:
String ^str = String::Format("{0,-25}{1,-15}{2,-15}", str1, str2, str3);
for values left-aligned.
-- modified at 15:35 Tuesday 8th August, 2006
|
|
|
|
|
Thank U very Much George,
I wish u all the best
Nagaraju
|
|
|
|
|
Hi..
Has anyone wrapped the ODBC Native API into a managed C++ class. From what I have researched natiive ODBC API is still the fastest way to fecth records.
Sk8tz
.NET Rules
|
|
|
|
|
Code Project Articles[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Is theer any api or code to play a continuous stream of PCM (wave)data...
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o°
»·'"`»* *☆ t4ure4n ☆* *«·'"`«
°o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
|
|
|
|
|
Hello
I have to use a Win32 API in a C# project (VS 2K5). I want to create a API wrapper class in C++. And then use it from my C# code.
I tried to use P/Invoke in C# to create a wrapper class, some of the methods didn’t work because Pointers to memory were not working..
QUESTION 1
Now how do I create a wrapper class, save it as dll and use it in C#. Please tell me whole procedure.
Because when I try to create a C++ project The VS2005 gives me a list of templates to choose from like “CLR Console Application” “Windows Forms Application”, etc etc
Question 2
My project has a method that continuously reads a block of PCM data from an external radio receiver connected to the computer through USB.
Is there and way to listen to that signal through C#. IS PCM just like audio signal … if not how do I convert it into audio.
------------------------------------------------------------------------------------------------
I am writing an example of the function I have to write and tell me what type of project I have to make and what procedure I have to follow.
#include "stdafx.h"<br />
#include <stdio.h><br />
#include <windows.h><br />
<br />
typedef int (__stdcall *FNCOpenRadioDevice)(int iDeviceNum);<br />
typedef BOOL (__stdcall *FNCCloseRadioDevice)(int hRadio);<br />
typedef BOOL (__stdcall *FNCSetAtten)(int hRadio, BOOL fAtten);<br />
typedef BOOL (__stdcall *FNCSetPower)(int hRadio, BOOL fPower);<br />
typedef BOOL (__stdcall *FNCSetAGC)(int hRadio, int iAGC);<br />
typedef BOOL (__stdcall *FNCCodecStart)(int hRadio,void (__stdcall *CallbackFunc)(void *),<br />
void *CallbackTarget);<br />
typedef BOOL (__stdcall *FNCCodecStop)(int hRadio);<br />
typedef unsigned int (__stdcall *FNCCodecRead)(int hRadio,void *Buf,unsigned int Size);<br />
<br />
typedef struct {<br />
int hRadio;<br />
FILE *IFFile;<br />
FNCCodecRead CodecRead;<br />
} CallbackContext;<br />
<br />
void __stdcall CodecCallback(void *Target)<br />
{<br />
unsigned int i;<br />
char Buf[4096];<br />
CallbackContext *Ctx=(CallbackContext *)Target;<br />
<br />
while ((i=Ctx->CodecRead(Ctx->hRadio,Buf,sizeof(Buf)))!=0) <br />
fwrite(Buf,i,1,Ctx->IFFile);<br />
}<br />
int main(int argc, char* argv[])<br />
{<br />
HMODULE dll=LoadLibraryA("wrg303api.dll");<br />
if (!dll) {puts("WRG303API.DLL not found !"); return 0;}<br />
<br />
FNCOpenRadioDevice OpenRadioDevice=(FNCOpenRadioDevice)GetProcAddress(dll,"OpenRadioDevice");<br />
FNCCloseRadioDevice CloseRadioDevice=(FNCCloseRadioDevice)GetProcAddress(dll,"CloseRadioDevice");<br />
FNCSetAtten SetAtten=(FNCSetAtten)GetProcAddress(dll,"SetAtten");<br />
FNCSetPower SetPower=(FNCSetPower)GetProcAddress(dll,"SetPower");<br />
FNCSetAGC SetAGC=(FNCSetAGC)GetProcAddress(dll,"SetAGC");<br />
FNCCodecStart CodecStart=(FNCCodecStart)GetProcAddress(dll,"CodecStart");<br />
FNCCodecStop CodecStop=(FNCCodecStop)GetProcAddress(dll,"CodecStop");<br />
FNCCodecRead CodecRead=(FNCCodecRead)GetProcAddress(dll,"CodecRead");<br />
<br />
int hRadio=OpenRadioDevice(0);<br />
if (!hRadio) {puts("No WR-G303 device could be opened !");FreeLibrary(dll); return 0;}<br />
<br />
if (SetPower(hRadio,TRUE)) puts("The device is turned ON"); else puts("The device failed to turn ON");<br />
if (SetAtten(hRadio,FALSE)) puts("The attenuator is OFF"); else puts("The attenuator failed to turn OFF");<br />
if (SetAGC(hRadio,3)) puts("The AGC is FAST"); else puts("The AGC failed to switch");<br />
<br />
FILE *f=fopen("IF2.pcm","wb");<br />
<br />
CallbackContext Ctx;<br />
<br />
Ctx.hRadio=hRadio;<br />
Ctx.IFFile=f;<br />
Ctx.CodecRead=CodecRead;<br />
if (!CodecStart(hRadio,CodecCallback,&Ctx)) puts("Codec streaming couldn't be started!");<br />
else {<br />
puts("Codec streaming properly started!");<br />
while (!ftell(f) ) <br />
{<br />
}<br />
CodecStop(hRadio);<br />
fclose(f);<br />
}<br />
<br />
if (CloseRadioDevice(hRadio)) puts("The device is closed properly"); else puts("The device failed to close");<br />
<br />
FreeLibrary(dll);<br />
<br />
return 0;<br />
}<br />
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o°
»·'"`»* *☆ t4ure4n ☆* *«·'"`«
°o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
|
|
|
|
|
t4urean wrote: Now how do I create a wrapper class, save it as dll and use it in C#
Create a "Class Library" project using Visual C++.
t4urean wrote: Please tell me whole procedure.
That is not what the forums are for "whole procudure". There are articles here on Code Project and also on msdn.microsoft.com that show the "whole procedure".
|
|
|
|
|
I have a strange problem that has been driving me up the wall. I created a SSCCE that shows my problem. Compile this with cl /EHsc /clr <filename> :
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
#include <iostream>
int main()
{
using System::Windows::Forms::DialogResult;
using System::Windows::Forms::FolderBrowserDialog;
using System::Windows::Forms::MessageBox;
double d;
std::cin >> d;
FolderBrowserDialog* fb = new FolderBrowserDialog;
if (fb->ShowDialog() == DialogResult::OK) {
MessageBox::Show(fb->SelectedPath);
}
}
When I run this program as is, after entering a number on the command line, the FolderBrowserDialog comes up blank. However, if I comment out the std::cin >> d; line, then the FolderBrowserDialog works fine. Does this happen for anybody else? Or am I misusing the mixture of managed and unmanaged code? I am using VS .NET 2003 on Windows XP SP2, with the .NET 1.1 Framework.
--
Marcus Kwok
|
|
|
|
|
OK, I found a solution that seems to work. In the article Mix and Match: Integrate Windows Forms Into Your MFC Applications Through C++ Interop (http://msdn.microsoft.com/msdnmag/issues/06/05/MixAndMatch/[^]), I found this piece of advice:If you compile with the /clr option, your code implicitly depends on the multithreaded DLL version of the C runtime libraries (CRT). This means that all files in your project—even those compiled without /clr—must use the multithreaded DLL version of the CRT. Adding /MD to the compile command seems to fix it. Incidentally, this also seems to fix my earlier problems (here and here).
--
Marcus Kwok
|
|
|
|
|
Hi,
I've got a problem with my wrapper class and my wrapped native object:
How can the wrapper be notified if the native object inside is modified?
Background: I want to wrap a library where an observer pattern is implemented. There the native observer observes a native subject where it was registered. If the subject notifies the registered observers about a change my observer-wrapper was not notified.
What should I do to make this work? I thought about something like function pointers and delegates but I think I'm on the wrong track.
Or is it possible to pass a managed object as a parameter to a native object's function?
Example:
class AbstractSubject
{
public:
virtual ~AbstractSubject() {};
virtual void Attach(IObserver*);
virtual void Detach(IObserver*);
virtual void Notify();
protected:
AbstractSubject() {};
private:
std::vector<IObserver*> observers;
};
class IObserver
{
public:
virtual ~IObserver() {};
virtual void Update(AbstractSubject* theChangedSubject) = 0;
protected:
IObserver() {};
};
As you can see the IObserver is a interface class. This interface class is wrapped by a managed c++ interface-class. The native observer object registeres itself on the Attach(IObserver*) -method and is added to the observers -vector.
If the Nofify() -method of the subject is called the subject iterates over the observers-vector and calls Update(this) (observerobject->Update(this)) on the observer object to notify the observer that something changed.
But how can I add now my managed class or my managed object to the subject to be notified? Please correct me when I'm wrong but I think I cannot pass the managed-observer-handle to the native method to notify the managed observer.
BTW: I don't have to source code for the native classes. I only have got a DLL-file, a LIB-file and some header-files to access the classes in the native lib.
Any help would be appreciated.
Thanks a lot for you help!
Best regards,
Ralf
|
|
|
|
|
I am a new C++ video game design student. I'm really not loving this C++ class cause my teacher is from tiawan and only knows like 100 words of english and when he puts them together in a sentence they are in the wrong order anyways. So i'm NOT understanding what it is he is telling us or asking of us. But i need help, or i need the code written for me or something. but we are on vectors and he wants us to make a list using 'iterators' that we can input our favorite video games. list them, and erase them. then he wants a quit fucntion to end the program.
can someone please help me.
|
|
|
|
|
You should also learn to read sticky notes in forums. This forum is for C++/CLI questions only, your question is off topic here. It's generally rude to crosspost, in any case.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
You are not clear, but it sounds like you want the Standard Template Library (STL)
It a simple and easy to use library. here is a simple example for you, straight from the help files which you should probably read first before posting a question:
#include "stdafx.h"
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> myVector; // an empty string vector
vector<int>::iterator myIter; // an iterator for the string vector
myVector.push_back( 0 );
myVector.push_back( 1 );
myVector.push_back( 2 );
myVector.push_back( 3 );
myVector.push_back( 4 );
myVector.push_back( 5 );
for ( myIter = myVector.begin(); myIter != myVector.end(); myIter++ )
{
cout << " " << *myIter << endl;
}
cout << endl;
return 0;
}
OrcBighter2
|
|
|
|
|
I have a problem setting a class constant in my C# assembly to the value of a constant in a managed C++ class. The compiler does not seem to recognise that the managed C++ class constant is constant. The error message is shown below:
#error = "The expression being assigned to 'MyAssembly.SMyFooBar.bahName' must be constant
I am writing in Visual Studio 2003 on WinXP SP2 with .Net Framework V2.0.50727
What Have I done wrong here?
The reason for this attempt is that the majority of our code is unmanaged c++, which uses a glabal header file to set values through a number of projects.
I wish to include this header in our various new C# projects, and thus avoid double maintenance. If the header file changes, all that is needed is a code recompile, at least in theory.
To do this I wrapped the header file inside a managed c++ class to create a dll. I then included this dll as a reference in my C# project so that I could use it to initialise some c# constants, thus:
-- unmanaged C++ header
// CPPHeader.h
#ifndef CPPHeader_defined_hpp
#define CPPHeader_defined_hpp
#define MAX_FOOBARS 3
#define FOOBAR_NAME "Foo Bar"
#endif // CPPHeader_defined_hpp
---------------------
-- managed C++ class
//MyManagedClass.h compiled to a DLL
#pragma once
#include "CPPheader.h"
using namespace System;
public __gc class SMyManagedClass
{
public:
static const int maxFooBars = MAX_FOOBARS;
static const String* FooBarName = FOOBAR_NAME;
};
--------------------------
-- C# assembly
//MyFooBarAsembly.cs
using system;
using SMyManagedClass;
namespace MyAssembly
{
public class SMyFooBar
{
public const int maxBahs = SMyManagedClass.SMyManagedClass.maxFooBars;
public const string bahName = SMyManagedClass.SMyManagedClass.FooBarName;
}
}
OrcBighter2
|
|
|
|
|
No way, your mc++ declaration says the constans are static. static are not considered as constants. Thats why teh error.
static const int maxFooBars = MAX_FOOBARS;
static const String* FooBarName = FOOBAR_NAME;
So to overcome this, you have to remove taht static. but then you cant use the values without creating the instance. so the alternative is to declare an enum for that insted of a class.
public enum class SMyManagedClass<br />
{<br />
maxFooBars = MAX_FOOBARS<br />
}
But here inside enum u cant use strings. So for string items u can create a managed class and inside a hash table to host all tthe strings. then an index enum can puul the corresponding string,...
cheers..Milton Kb
|
|
|
|
|
Thanks for your reply.
Sorry, but I don't quite see what you are getting at.
The const in mc must be static in order to initialise it with a value.
For me, the end result must be that a string constant defined in the C# assembly must be able to be initialised to the value of a constant from the managed C++ class.
The code I provided works fine for integer constants, however, the C# does not regard the C++ string constant as a constant, and thus will not allow me to initialise the C# constant to that value.
|
|
|
|
|
What is the best way to integrate an MFC-component in a .Net application?
The MFC-component I want to use resides in an mfc-dll and consists of many c++ classes with big usage of the MFC-classes. I tried so far to use IJW with MC++ wrapper classes but the application crashes all the time in some new and I don't want to use PInvoke because then I loose the object oriented design. How about converting the MFC-component into a COM object? Can I use the MFC-component this way in a .Net application?
All suggestions are welcome.
Cheers
gunag
|
|
|
|
|
U should be able to make it working through IJW. whats the erro u are getting? Though converting to COM is a possible alternative, as far as workload is concerned IJW is best. Performancewise also IJW is better than Com interop according to msdn.
cheers..Milton KB.
|
|
|
|
|
Hi Milton KB,
I get lots of crashes related to new operators. Each time I allocated with new a CDC object, it might crash. I have the feeling that during the new operation there might be a conflict between the managed and unmanaged heap. Do you have any idea what i could do in this case?
|
|
|
|
|
There shouldn't be any crash normally. can u b more specific by posting some code which causes error..
Milton KB
|
|
|
|
|
Im trying to create an AsyncCall back instance but i get a weired error :
Code:
Static void function()
{
...
AsyncCallback* callback = new AsyncCallback(TestMethod, &TestMethod);
...
}
the error is:
error C3363: 'void ClientRequestReceived(System::IAsyncResult __gc *)' : cannot create a delegate handler for 'System::AsyncCallback' from a non-member function or a member of an unmanaged class
how do i fix this error?
Thanx in advance
Upon my end shall i begin?
Forsaking all i've fallen for..
i rise to meet the END!!
|
|
|
|
|
In C/C++ can any "macro" take variable number of arguments? Is it possible any way?
Pradosh
|
|
|
|
|