|
cool!
now what?
Please read this[^] before posting something.
modified 16-May-14 5:04am.
|
|
|
|
|
|
I am using a dll developed in Visual c++ in to the C# application. It works fine with Visual Studio 2005. But when using the same with Visual Studio 2012, it causes the error.
myDll.h
#ifndef _MYDLL_H
#define _MYDLL_H
extern "C" _declspec(dllexport) char* __stdcall getName();
#endif
myDll.cpp
#include "stdafx.h"
#include "mydll.h"
extern "C" __declspec(dllexport) char* __stdcall getName()
{
return "Hello !!!";
}
the above code produces the mydll.dll. I used to copy the dll into newly created c# windows application into bin/Debug directory. The c# application code is somewhat like
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace sysWinApp
{
public partial class Form1 : Form
{
[DllImport("myDll.dll")]
static extern string getName();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = getName();
}
}
}
the windows form consists of a label and a button. By clicking the button, it should display the content on the label, which is accessed from the string returned from the dll function. It works fine with VS2005 but the same didn't happen with VS2012.
The C# win app of VS2012 prompts the message that it "has stopped working".
any ideas to resolve this ?
|
|
|
|
|
I'm not sure how you ever got this working in VS2005. There are two issues.
First: You can't return a pointer to a char array that you allocated on the stack. The moment the funtion returns the memory is deallocated and a pointer to an unallocated address is returned. You need to allocate the memory using new. This implies that you need to export an additional function that receives a pointer and deletes it (to prevent memory leaks).
Second: In your C# application you define (incorrectly) that the imported function returns a (managed) string. Actually it returns a char pointer. I think you will need an unsafe block to receive the char pointer, initialize a new managed string with it and then delete the char pointer (using the function mentioned above). After that you can assign the managed string to the label.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
|
The C dll is a 32bit dll (as was your VS2005 application), while your VS2012 application is a 64bit application (or a bitness-ignoring application on a 64bit system).
|
|
|
|
|
My application is made only in English and i want to switch it to multilingual version . But instead of user changing default language in regionaal settings i gave my application a "ToolStripMenuItem" called langauge and added a submenu for Arabic , Korean and English version .
As far i am aware three things are required -:
1.Writing a code in click event of that Langauage subemenu say "Arabic"
2.Creating a corresponding resx file
3.Also i had set the Form localizable property to "True"
This is the code i added to my Program in Form1()
CultureInfo CurrentLocale;
public Form1()
{
InitializeComponent();
valueInit();
}
private void ChangeLanguage(string lang)
{
CurrentLocale = new CultureInfo(lang);
foreach (Control c in this.Controls)
{
ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
resources.ApplyResources(c, "$this");
RefreshResources(this, resources);
}
}
private void RefreshResources(Control ctrl, ComponentResourceManager res)
{
ctrl.SuspendLayout();
res.ApplyResources(ctrl, ctrl.Name, CurrentLocale);
foreach (Control control in ctrl.Controls)
RefreshResources(control, res);
ctrl.ResumeLayout(false);
}
private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
ChangeLanguage("en-US");
}
private void arabicToolStripMenuItem_Click(object sender, EventArgs e)
{
ChangeLanguage("ar-SA");
}
private void koreanToolStripMenuItem_Click(object sender, EventArgs e)
{
ChangeLanguage("ko-KR");
}
Second i added a resx file called Form1.ar-SA.resx and Form1.kr-KO.resx
However when i run my application and try clicking on language Arabic it still does not change anything .
can someone please help me to find where i went wrong or what am i missing ?
diwesh saxena
|
|
|
|
|
In your ChangeLocale function, also try at the top of the function:
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(lang);
|
|
|
|
|
Thanks for your investing your time . There is no ChangeLocale function ... Are you referring to Changelanguage Function ?
diwesh saxena
|
|
|
|
|
I have a WCF web service (https). Inside of that web service, I call another 3rd party web service (http) and get a large amount of data back (12MB) -- a jpg image. The client is getting an exception during my processing of that image: An existing connection was forcibly closed by the remote host. I've put logs on every line in the method and tracked it down to:
gr.DrawImageUnscaledAndClipped(img, rect);
IIS just simply kicks out the process during this call. I've tried wrapping this call in a try / catch to see the real exception, but its not throwing an exception, just simply kills the client's call with the above exception.
Anybody ever seen this before?
img is quite large jpg 32bit (9MB), 14,800 x 14,800 and the drawing surface is 15000 x 15465.
I was able to draw this large when I was calling the 3rd party web service via REST, but had to switch over to thier WCF version for added functionality. This of course comes with added overhead (img is transmitted as base64 vs. just a binary stream) and it requires running in an STA thread for some unknown reason.
I watched the server in task manager and the process craps out with the memory at about 1GB. It has gone higher then that with the REST version. I was able to process about 8 of these images at a time. Now I cannot process even 1 at a time.
The server is 64bit and has 18GB of RAM with only 11% consumed at idle.
If I comment out the DrawImage call, I get the 15000 x 15465 image back in its processed state (minus of course the content).
Any ideas? Why is IIS killing my call without even throwing an exception on the server side?
|
|
|
|
|
On what exactly do you try and draw the image?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Hi,
Just a normal Bitmap:
Bitmap bmp = new Bitmap(cx, cy + 465);
using (Graphics gr = Graphics.FromImage(bmp))
{
gr.FillRectangle(new SolidBrush(System.Drawing.Color.White), 0, 0, cx, cy + 465);
Rectangle rect = new Rectangle((cx - img.Width) / 2, 465 + ((cy - img.Height) / 2), img.Width, img.Height);
gr.DrawImage(img, rect.Left, rect.Top);
gr.DrawImage(Properties.Resources.Header, 0, 0, cx, 465);
The second DrawImage call works fine, but thats a smaller image.
|
|
|
|
|
Yes, but you are inside a web service, so on what UI are you drawing the image?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
There is no UI. The client calls my web service. My web service calls the 3rd party web service to get a jpg. I then do some post processing and return it to the client as a byte array. My web service is a wrapper around the 3rd party web service. The post processing is where my issue is. The jpg from the 3rd party service is 14800x14800. I create a 15000x15465 bitmap and draw the other bitmap onto this bitmap and draw some other stuff as well. All the annotations are drawing correctly. It is the gr.DrawImage() call that is crapping out the clients web service call for some reason. It didn't when I was using a different version of the 3rd party service.
|
|
|
|
|
Did you checked the image you got from the 3rd party? Can it be defected?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Do a simple test: your web service receives the base64 encoded image from the ThridParty WCF service, creates a "real" image from it, and sends it to the client. Now open it on the client: does that work? Does the image look as you expected it?
|
|
|
|
|
Yup. Tried saving out the image and it looks fine. The Base64 string is 12MB and the decoded image is 9MB, so I don't know if I'm running out of memory. The other version of the service, the REST one, just returned the image as a stream, so I didn't have the 12MB of extra stuff. I can't even create the 15000x15465 drawing surface on my dev machine as it runs out of memory (even with the old REST implementation that ran fine on the web server). On my dev machine though, at least I get an exception when I try to create the drawing surface. On the web server, there is no exception, IIS just closes the connection?!?
Weird though, the 12MB is in a String so it should be in the managed heap while the Image is all in the unmanaged heap, right?
I was watching Task Manager during the call and the memory usage went up to 1GB when IIS killed it. I don't have any limits set. I've seen the memory go up to 2 or 3GB with the working REST implementation (had 8 threads going on the client -- so 8 simultaneous calls into IIS and it didn't run out of memory or kill connections).
|
|
|
|
|
SledgeHammer01 wrote: so I don't know if I'm running out of memory. A bitmap with that depth and size - create one using a paint-application, save it and check it's size.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
That looks like just below 900MB.
|
|
|
|
|
Hello. I have problem to execute UPDATE query in C# winforms app. I have a table without primary key. When I select a row in listview, records will show in textboxes, and i change text in textboxes and click update, it should update this row, but did not work. I dont know where is problem. Thanks a lot
Inserting and deleting is OK.
private void button3_Click(object sender, EventArgs e)
{
SqlCeCommand cu = new SqlCeCommand("UPDATE tblUsers SET userName = @userName, age = @age WHERE userName = @userName", cn);
cu.Parameters.AddWithValue("@userName", textBox1.Text);
cu.Parameters.AddWithValue("@age", textBox2.Text);
try
{
cu.ExecuteNonQuery();
Populate();
}
catch (SqlCeException excd)
{ MessageBox.Show(excd.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); }
}
|
|
|
|
|
You are setting usrname to "Pete" everywhere there's a record called "Pete". Unless you're changing the username to what it already is, it will not update.
I suggest you research what a primary key is, what it does, and why you would want one.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi friends,
I am working on a biomedical application. I need to import a 3D model
of heart and displaying it after rotation. I use C# and the model is
stored in a 3ds file (I have an obj file,too). I don't need high
performance, engines. I just need the simplest engine for rotating and
displaying this model.
I was wondering if you could help me.
I am looking forward to hearing from you,
|
|
|
|
|
If you're working with 3D and want to be able to use C# with it, I would take a look at Unity. It has all the functionality you will need, and then some.
|
|
|
|
|
It might be easier to just export the 3D model to a 3D PDF file. It can then be viewed and rotated with the standard Adobe PDF reader.
|
|
|
|
|
Such a solution works for me. the format is not important. How can I do it?
|
|
|
|