|
I can do it with a StringBuilder or like this,
<br />
byte[] buffer = new byte[512];<br />
<br />
unsafe<br />
{<br />
fixed (byte* pBuffer = buffer)<br />
{<br />
ret = theFunc(_o, pBuffer);<br />
}<br />
}<br />
The second Parameter is an out param, it gives me a path to a file. If i do it with a StringBuilder or with a pointer to a buffer, it is the same result. In a Windows Forms Application, the buffer is NOT empty, in a Windows Service the buffer IS empty.. I try it on different machines and with different user accounts (Local System, User etc.). In a service it won't work.The com interface is marshalled correct.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
-- modified at 17:29 Monday 16th April, 2007
|
|
|
|
|
Hi,
StringBuilder is the right way to go when the function wants to return a string
value; it would be better to have a buffer size too in the argument list
(it would then be set to StringBuilder.Capacity), but if the function does not
take such an input, you should provide a sufficiently large StringBuilder.
For a single file spec, I believe 512 is the Windows maximum.
When I must call a native function that does not take a buffer size, I provide
a StringBuilder[1024].
I am afraid it is the other, the first, argument, that is causing your problems.
|
|
|
|
|
Hi,
no the first argument is not the problem. I'm testing with a StringBuilder with a capacity from up to 10240 to ensure there is enough space.. but it don't work. That makes me crazy. So, i got a little Form Application with one button, on button click event i call the function and it works. When i do it in a ConsoleApp or a service it will not work. I don't think that my code is ugly.. i think here is something wrong with the hole frame. Is ther probably not enough or to much time between call and passing the function? Or could it be a Thread Problem?
|
|
|
|
|
OK, lets suppose the marshalling is all right.
two ideas:
1.
What is special about the service ? what is the string you expect to get ?
does it exist when there is no user logged in ?
2.
a simple test may not call the gc and work fine, what if the gc starts acting up.
Are you passing some pointer somewhere that needs to be pinned so the gc
does not MOVE the object ?
|
|
|
|
|
Another idea: check the STAThread/MTAThread situation for your different experiments.
It is an attribute that gets set automatically to your static Main() method.
BTW: Having the console app fail is good, it may allow you an easy debug with
Visual Studio...
|
|
|
|
|
Hello everyone,
Is it possible to create enumerations dynamically which we can manipulate or even create/destroy at run-time?
Best regards.
.:: Something is Wrong ::.
|
|
|
|
|
Yes it is possible. Look up Lightweight Code Generation.
That said, I'd question whether you truly need this; there's probably an easier way to accomplish your goal. What are you trying to do? I may be able to suggest a better alternative.
|
|
|
|
|
Well, for example, I would like to create a generic vehicle class, in which I should use a vehicle type enumeration. But when someone needs to extend this types he/she should add some ne vehicle types to the enumeration.
.:: Something is Wrong ::.
|
|
|
|
|
Use a list or a database rather than a dynamic enum.
|
|
|
|
|
Absolutely. However an enumeration is the wrong data type to use. A collection of some sort would do just as well. With the lists (i.e. ArrayList), you can even sort the list and do a binary search on the list to find out if the element exists. But I am thinking that you want to do a direct comparison, which means that you can do a list.Equals(value) which returns a true or a false.
Phil
|
|
|
|
|
let's say i want to go to address 377DC in program.exe and change it's value to 60? (just a fictional example), how can I do it?
|
|
|
|
|
You can acquire pointers to memory locations use standard pointer syntax ala C++. It just has to be done in an unsafe context using the unsafe keyword.
|
|
|
|
|
um..have you got any examples? cause i haven't been able to find any references to that subject
|
|
|
|
|
sharpiesharpie wrote: i haven't been able to find any references to that subject
What did you search on? MSDN: unsafe[^]
|
|
|
|
|
Are you trying to change something in some other running program?
Or you trying to this in an application written by you?
|
|
|
|
|
In another program (games). I just want to learn the whole thing (used to build trainers etc.).
|
|
|
|
|
I knew that you can use DLL Injection in VC++ however I am not sure how to achive it in VC#.
btw I dont think you can do it in any NT based OS. That is the security model to stop one process to modify(tamper) some other process unless explicitly allowed.
Cheers,
Suresh
|
|
|
|
|
lol...ever heard of trainers? and you don't even have to go that far, just google "TSearch"...a memory searcher used to search a program's memory and change values in it.
|
|
|
|
|
|
It's not excellent...it doesn't help me ><
I still need to know how to do it \=
|
|
|
|
|
A process can only access its own memory, so you need to inject a library into the target process. I don't think you can inject the .NET runtime into a running process (though another injected library may load .NET), so what you're trying to do is probably impossible with C#. There are articles here on CodeProject that show how to do it with C++.
|
|
|
|
|
hi, I am getting this error when generating pdf docs from crystal report app (C# 2.0).
CallbackOnCollectedDelegate was detected
Message: A callback was made on a garbage collected delegate of type 'CrystalDecisions.ReportAppServer.DataSetConversion!CrystalDecisions.ReportAppServer.DataSetConversion.DataSetConverter+CrdbAdoPlusDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
I am creating pdf docs from crystal report app which is being hosted in console app. I have a report document with 6 sub reports. I am poppulating these sub reports on the report document by pushing a datatable/dataset. In doing that, I am instantiating report document once as a global variable. Then each next pdf doc will be using that same report document object but I am loading a new report doc every time new report(pdf doc) needs to be generated.
After about 20 to 30 docs are generated I get error listed on top "CallbackOnCollectedDelegate was detected" with detail description also provided earlier.
Reading this error made me think that if I put some kind of delay (1000 miliseconds) before loading report, it would help but did not solve my problem. It did went further than 20 to 30 docs to 104 docs but that error did come back.
I would appreciate if some one can shed some light
Thanks
Needy
|
|
|
|
|
Hi,
the message is clear: some code is calling back on an object that no longer
exists. This happens because the PDF reporter is still using some event, while
you are changing the report document.
In simple sequential situations, a useful work-around may be to keep the previous
document alive, so the following pseudo-code may show what I mean:
DOC myDoc;
DOC myPreviousDoc;
void doMyDocuments() {
while(moreDocumentsToDo) {
myPreviousDoc=myDoc;
myDoc=new DOC();
... attach delegates
... process document
}
myPreviousDoc=null;
... maybe more processing
}
|
|
|
|
|
If I do this, do I need to put the 1000 milisecond detail between two report processing? And, would it release the resources or just give it some time to process the events?
The reason why I am questoning this approach is that, i am looping through list of records and checking if data exists. Before doing this, i am setting loading report document in to the variable i have already decalred and using it. So if data doesn't exist for perticular id then I am immediately skipping that perticular record and get the next record from the datatable and try to process that record (and once again, I will load the report document in to the report document object I was using before).
Also, If I recreate the report object by doc = new doc() when I am looping through it takes a lot of time to process the whole list.
Is there another way where I can use the same doc and still not get the error.
Like
declare ReportDocument doc = new ReportDocument() as global variable within class then use this doc in the methods but keep loading different docs in to this same object so we can do away with reinitializing the reportdocument object and processing would be faster.
Also, problem with creating a new report object is that, crystal report has limitation of number of new object set to 75 (named PrintJob limit which is registry entry item). I tried changing the limit to 1000 to 10000 and still didn't help so then I tried instantiating report object only one during whole process and just loading a different document everytime I need a new report to be generated.
Please elaborate.
-- modified at 16:38 Monday 16th April, 2007
Thanks
Needy
|
|
|
|
|
OK, then what about this:
have two documents (instead of one) and use them in ping-pong
so code could be like this:
DOC doc1=new DOC();
DOC doc2=new DOC();
void doAllDocs() {
while (moreDocs) {
DOC temp=doc1;
doc1=doc2;
doc2=temp;
... handle one document, using doc1 (dont touch doc2 at all)
}
The net result is while processing doc1, doc2 is still present to get
finished.
|
|
|
|