Click here to Skip to main content
15,510,280 members
Home / Discussions / C#
   

C#

 
AnswerRe: Issue with accessing object in background thread when converter value updates Pin
Super Lloyd13-Jul-16 18:48
Super Lloyd13-Jul-16 18:48 
AnswerRe: Issue with accessing object in background thread when converter value updates Pin
Slacker00713-Jul-16 23:45
professionalSlacker00713-Jul-16 23:45 
AnswerRe: Issue with accessing object in background thread when converter value updates Pin
Gerry Schmitz14-Jul-16 6:32
mveGerry Schmitz14-Jul-16 6:32 
GeneralRe: Issue with accessing object in background thread when converter value updates Pin
Imagiv14-Jul-16 7:26
Imagiv14-Jul-16 7:26 
GeneralRe: Issue with accessing object in background thread when converter value updates Pin
Gerry Schmitz14-Jul-16 8:06
mveGerry Schmitz14-Jul-16 8:06 
Questionc# network programming(Server /Client ) Pin
Mostafa_Hosseini13-Jul-16 7:44
Mostafa_Hosseini13-Jul-16 7:44 
AnswerRe: c# network programming(Server /Client ) Pin
Super Lloyd13-Jul-16 14:17
Super Lloyd13-Jul-16 14:17 
Question[SOLVED] System.AccessViolationException When Calling Dll Function Again Pin
Django_Untaken13-Jul-16 6:39
Django_Untaken13-Jul-16 6:39 
The problem was in the unmanaged DLL. But I really learnt a great deal about other topics such as BackgroundWorkers and TPL. Thanks all.

=======================

Hello There. I have this small DLL that takes input_name and output_name as parameters. It opens the input file, reads it and produces output file with the specified name after some processing.

I then call this function from C#. First time I call it, it runs fine. But second time around, it throws this exception

<br />
An unhandled exception of System.AccessViolationException occured in CSharpProgram.exe.<br />
Attempted to read or write protected memory.<br />


Here is what I am trying.
C#
[DllImport("MyDll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int Call_Dll_Main(string input, string output);

private void Button_Click(object sender, EventArgs ea)
{
   new System.Threading.Thread(new System.Threading.ThreadStart(Call_Dll_Function)).Start()
}

private void Call_Dll_Function()
{
    int nResult = Call_Dll_Main(txtInputFile.Text.Trim(), txtOutputFile.Text.Trim()); // HERE EXCEPTION COMES...FIRST TIME FINE...IT COMES SECOND TIME I CLICK THE BUTTON
}

What could be wrong? What am I missing here? Thanks for any input.

modified 14-Jul-16 11:34am.

AnswerRe: System.AccessViolationException When Calling Dll Function Again Pin
Dave Kreskowiak13-Jul-16 6:55
mveDave Kreskowiak13-Jul-16 6:55 
AnswerRe: System.AccessViolationException When Calling Dll Function Again Pin
Luc Pattyn13-Jul-16 9:33
sitebuilderLuc Pattyn13-Jul-16 9:33 
GeneralRe: System.AccessViolationException When Calling Dll Function Again Pin
Bernhard Hiller14-Jul-16 4:59
Bernhard Hiller14-Jul-16 4:59 
AnswerRe: System.AccessViolationException When Calling Dll Function Again Pin
Slacker00713-Jul-16 9:35
professionalSlacker00713-Jul-16 9:35 
AnswerRe: System.AccessViolationException When Calling Dll Function Again Pin
Bernhard Hiller13-Jul-16 22:42
Bernhard Hiller13-Jul-16 22:42 
AnswerRe: [SOLVED] System.AccessViolationException When Calling Dll Function Again Pin
Member 132605384-Nov-19 17:38
Member 132605384-Nov-19 17:38 
GeneralRe: [SOLVED] System.AccessViolationException When Calling Dll Function Again Pin
Django_Untaken11-Nov-19 21:49
Django_Untaken11-Nov-19 21:49 
AnswerRe: [SOLVED] System.AccessViolationException When Calling Dll Function Again Pin
Member 162142615-Apr-20 1:28
Member 162142615-Apr-20 1:28 
Questionthe action cannot be completed because the file is open in w3wp.exe Pin
Rocky Nandu12-Jul-16 22:05
Rocky Nandu12-Jul-16 22:05 
AnswerRe: the action cannot be completed because the file is open in w3wp.exe Pin
OriginalGriff12-Jul-16 22:30
mveOriginalGriff12-Jul-16 22:30 
AnswerRe: the action cannot be completed because the file is open in w3wp.exe Pin
Pete O'Hanlon12-Jul-16 23:49
mvaPete O'Hanlon12-Jul-16 23:49 
AnswerRe: the action cannot be completed because the file is open in w3wp.exe Pin
F-ES Sitecore13-Jul-16 0:40
professionalF-ES Sitecore13-Jul-16 0:40 
GeneralRe: the action cannot be completed because the file is open in w3wp.exe Pin
Rocky Nandu29-Jul-16 2:48
Rocky Nandu29-Jul-16 2:48 
QuestionHow To Wire Up This Event Pin
Kevin Marois12-Jul-16 15:42
professionalKevin Marois12-Jul-16 15:42 
AnswerRe: How To Wire Up This Event Pin
Super Lloyd12-Jul-16 17:43
Super Lloyd12-Jul-16 17:43 
GeneralRe: How To Wire Up This Event Pin
Kevin Marois13-Jul-16 7:14
professionalKevin Marois13-Jul-16 7:14 
GeneralRe: How To Wire Up This Event Pin
Super Lloyd13-Jul-16 8:07
Super Lloyd13-Jul-16 8:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.