|
Hi, I am new here, and I have a little question...
I am making a program, that does several things, but the pin point is when I create a shortcut. For easy coding, i was "forced" to use IWshShell and so on, and add a COM reference that enables me to do so. All goes well, until I come to a little problem, wherever my program goes Interop.IWshRuntimeLibrary.dll needs to go with him. I have searched for hours to find a way to attach it to main project or exe, but it seems impossible. Can someone help me to get a way to attach it, or turn into a lib and implement, or something that allow me to create shortcuts with that ease?
Thanks for you attention.
|
|
|
|
|
class MyNative{
public:
std::string GetANativeString(){
return "Some text";
}
}; Above class returns a std::string to the caller. I need to convert the returned string to a managed string(String^ ). I have done it, but want to make sure this is the correct method. Here it goes,
MyNative native;
String^ str = gcnew String(native.GetANativeString().c_str());
Console::WriteLine(str); System::String has an overloaded constructor which accepts a char* . Is this the correct approach or should I change GetANativeString() method to return a char* ?
|
|
|
|
|
std::string requires more overhead than const char*. Other than that, I don't see any problems with using either one. Each one is appropriate.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi,
My application working fine in the dev environment.But in the testing /production environment
it is not working because that environment has only
windows server 2003
IIS
I have prepared a MSI which will automatically install .net2.0 framework
In my application I have Used some microsoft VC++ dll's also along with .net dll's.
Now Iam getting "RUNTime Error" pop-up screen message as below
" The Application has been terminated in an Unusual Way"
On googling i came to know that some dll's like msvcrt.dll of windows server 2003 has to be changed...But Iam not pretty sure about it..
In Production/test environment there is only framework installed ,but there is no visual studio installed on it.may be due that this error may occur...
So kindly post your suggestions and views to help me
|
|
|
|
|
Don't cross post. You are being rude.
led mike
|
|
|
|
|
Hiho
i have got a question concerning a application i am working on. I have got a old former native MFC Application for which i enabled the /cli switch in Visual Studio. From this application i try to call managed code. So there cannot be used System.Windows.Forms from this side of code to show a simple form. i created a new managed project with a simple class which creates a Form. I am now calling this class from the /cli MFC Application and it crashes. When i am debugging the call of the C# .Net Class, it seems to be ok but when the Form is created the debugger jumps at this point
private System.ComponentModel.IContainer components = null;
and the complete application sometimes the Studio too crahes. So is it not possible to call Forms from MFC generally or am i doing some stupid stuff ?
Greetings Torben
modified on Friday, September 19, 2008 8:17 AM
|
|
|
|
|
ToSchi98 wrote: So is it not possible to call Forms from MFC generally or am i doing some stupid stuff ?
Stupid stuff? Nah. Incorrect maybe
Not only can you call c# code from your managed C++ app, you can also host
a Windows Form user control in your MFC app.
Using a Windows Form User Control in MFC[^]
As far as your specific problem, it's impossible for me to
guess without seeing what you're doing.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hiho and thanks for the help,
Yes you are right i try to describe my problem a little bit more precisely. I think the code will make it easier to understand. I do not have to host a UserControl i think so. I only want to Show a normal Windows.Forms.Form from a C# Sharp Assembly which is referenced in the MFC CLI application to use a Microsoft ReportViewer, reporting some stuff from the Application. Is this possible in general that way or will i have to host this form too ?
Greetings Torben
//MFC Application with CLI enabled
namespace::Formstarter ^CSharpForm = gcnew namespace::Formstarter();
CSharpForm-> SomeFormMethod();
//C# Assembly
public class Formstarter
{
public Formstarter()
{
FormToStart Started = new FormToStart()
Started.show();
}
}
//Class Form
public partial class FormToStart : Form
{
public SpliceReporter()
{
InitializeComponent();
}
//Not in the partial class
public SomeFormMethod()
{
//Do something
}
}
|
|
|
|
|
Are you sure the MFC app is finding the assembly with the
form in it OK? Are they in the same folder?
I just tried this and it worked fine for me
(note I changed both project output directories
to the same folder!):
C#
1) Created a control library project with the app wizard
2) Added a form
3) Added your Formstarter class and altered it to create my form class
C++
1) Created an MFC dialog app project with the app wizard
2) Changed settings to compile /clr
3) Added a button to the dialog, along with a button clicked handler.
4) Added a reference to the C# DLL (created above) to the project
5) Added code in the button click handler (1 line) to create a Formstarter
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the help again Mark. Yes you are right the same you did, works for me too. After you told me that it should work in general i was able to focuse an other things which cause that my app is not running.
I am developping on Win XP with VS 2008. The .Net Extension is written for the 2.0 Framework. On my developper system it works and no error is upcoming but if i put it on my target system Win2K SP4 Framework 2.0 with SP1 a microsoft error still occurs. When i put my .Net app and use ist from another .Net app instead of the MFC is works correctly so i think no Dlls are missing on the target pc. When i use a new MFC project instead of the old one it starting the .Net app everthing works fine too. If i put the call in the OnCreate Function of the main dialog of the MFC app i have to extend, it works also correct. But it does not work in my OnClickButton-method where it has to do. At the moment i am a little frustrated because i don´t know what to do anymore. I cannot debug the app because the only thing i get is this Microsoft Error. Anyone an idea perhaps ?
Greetings Torben
|
|
|
|
|
ToSchi98 wrote: I cannot debug the app because the only thing i get is this Microsoft Error
What's the exact error?
ToSchi98 wrote: it does not work in my OnClickButton-method where it has to do
Are you sure your click handler is getting called?
I guess getting it to run so you can debug it will help
find that out
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok Mark i finally found the error. Below there is code of the function which is called in the OnInit() method of the Dialog from which the call to the C# dll is triggered. So far so good. The final Software works on XP and Vista (both VS Studio 2008 installed) and "with this function". On Win2K with Framework 2.0 SP1 it doesn´t work. When i comment these method out it also works on Win2K. I don´t really know why this happens and i only get an error report i can send to MS with the hint that something crashes in the mswks dll. I did not spend attention to this method for a long time because nothing everything seems to be ok there was never a crash at this point.
Greetings Torben
PS: I am sorry but in the whole very big program inherited from a very nice guy not one line of documentation can be found
CString CSpliceCheckerDlg::GetVersionInfo()
{
CString csRet;
HMODULE hLib = AfxGetResourceHandle();
HRSRC hVersion = FindResource( hLib,
MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION );
if (hVersion != NULL)
{
HGLOBAL hGlobal = LoadResource( hLib, hVersion );
if ( hGlobal != NULL)
{
LPVOID versionInfo = LockResource(hGlobal);
if (versionInfo != NULL)
{
DWORD vLen;
BOOL retVal;
LPVOID retbuf=NULL;
static TCHAR fileEntry[256];
VS_FIXEDFILEINFO *pFixedValue;
_stprintf(fileEntry, _T("\\"));
retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen);
if (retVal) {
pFixedValue = (VS_FIXEDFILEINFO *)retbuf;
int i1 = pFixedValue->dwFileVersionMS;
int i2 = pFixedValue->dwFileVersionLS>>16;
int i3 = (pFixedValue->dwFileVersionLS&0xffff);
if (!i3) {
csRet.Format(_T("%d.%d"), i1, i2);
}
else {
csRet.Format(_T("%d.%d.%d"), i1, i2, i3);
}
}
}
}
UnlockResource( hGlobal );
FreeResource( hGlobal );
}
return csRet;
}
modified on Thursday, September 25, 2008 2:57 AM
|
|
|
|
|
What is that code supposed to do? It doesn't even return anything.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Try this:
CString CSpliceCheckerDlg::GetVersionInfo()
{
CString csRet;
TCHAR szAppName[MAX_PATH];
TCHAR szSubBlockName[256];
DWORD FVHandle;
UINT nSize;
BYTE *pData = 0;
::GetModuleFileName(AfxGetResourceHandle(), szAppName, sizeof(szAppName) / sizeof(TCHAR));
DWORD dwSize = ::GetFileVersionInfoSize(szAppName, &FVHandle);
if (dwSize)
{
pData = new BYTE[dwSize];
if (::GetFileVersionInfo(szAppName, FVHandle, dwSize, pData))
{
VS_FIXEDFILEINFO *pFixedFileInfo;
_tcscpy_s(szSubBlockName,_T("\\"));
if (::VerQueryValue(pData, szSubBlockName, (void **)&pFixedFileInfo, &nSize))
{
int i1 = (pFixedFileInfo->dwFileVersionMS >> 16) & 0xFFFF;
int i2 = pFixedFileInfo->dwFileVersionMS & 0xFFFF;
int i3 = (pFixedFileInfo->dwFileVersionLS >> 16) & 0xFFFF;
int i4 = pFixedFileInfo->dwFileVersionLS & 0xFFFF;
csRet.Format(_T("%d.%d.%d.%d"), i1, i2, i3, i4);
}
}
delete[] pData;
}
return csRet;
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark
I tested the code you posted above an it works fine. The code you posted seems clearly to me and i think i understand the problem of the old method in general (not exactly the point of error) which was used before but this bug was very very hard to find for me because i did not search on the right place for a long time . i do not exactly know why this error occurs at the point when the .net app was started and why it does not occur with a normal .net form without any reportform. I would have expected this error when initialize this mfc dialog. However a big "thank you" from my side for the help and time you spent.
Greetings Torben
Edit: Sry i forgot the return value and the last bracket in my i postet before. Changed it.
|
|
|
|
|
Hi all,
How to create a C# control (using VC# 2008 .Net) which can be used in any language (mainly in VC++ 2008 .Net)?
Please guide me.
I appreciate any and all comments and suggestions.
Thanks in advance.
Regards,
Aniket A. Salunkhe
|
|
|
|
|
What is a C# control?
If you build a library using C#, then all public classes in
that library can be consumed by any of the .NET languages.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Thanks for reply.
Mark Salsbery wrote: consumed by any of the .NET languages.
I want to add my 'Windows Form Control Library' (i.e. VC#.Net 2008 ActiveX Control) in my MFC Application of VC++.Net 2008.
Thanks & Regards,
Aniket A. Salunkhe
|
|
|
|
|
Aniket Salunkhe wrote: i.e. VC#.Net 2008 ActiveX Control
I don't know about ActiveX controls, but an ActiveX control
written in c# should work just like any other ActiveX control...
that's what they're designed to do
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Is there any way to design '.ocx' in VC#.net?
Because I can't register '.dll' VC# activeX control.
Thanks & Best Regards,
Aniket A. Salunkhe
|
|
|
|
|
Hi all,
I found something to work with MFC application,
http://msdn.microsoft.com/en-us/library/b1kyh79x.aspx[^]
Thanks for your support too.
Now I am trying to integrate it with my MFC Application & Control, as I want to add mutiple control dynamically in MFC Dialog.
But I appreciate any other better suggestions.
Thanks & Best Regards,
Aniket A. Salunkhe
|
|
|
|
|
I guess I'm confused - do you need an ActiveX control or a
Windows Forms control?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: ActiveX control or a
Windows Forms control
What is difference between these 2?
I want to create a UserControl in C#. eg Analog Clock Control in C# with some properties.
|
|
|
|
|
|
Any control you create in C#, or even VB.NET, can be used by the other .NET languages. You have to add a reference to the .dll containing your control.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|