.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

p/invoke acdbEntmod failure

4 REPLIES 4
Reply
Message 1 of 5
275171906
701 Views, 4 Replies

p/invoke acdbEntmod failure

hello everyone:

 

i want to p/invoke acdbEntmod method in NETAPI and the codes goes as follows,could u give me some sugguestions? 

 

public static class ObjectIdEx
{
#if ACAD2014
[DllImport("acdb19.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AEAY01_JVAcDbObjectId@@@Z")]
extern static public ErrorStatus acdbGetAdsName(out Int64 entres, ObjectId id);

[DllImport("acCore.dll", CallingConvention = CallingConvention.Cdecl)]
extern static IntPtr acdbEntGet(out Int64 e);

[DllImport("acCore.dll", CallingConvention = CallingConvention.Cdecl)]
extern static void acdbEntMod(IntPtr ptr);

[DllImport("acCore.dll", CallingConvention = CallingConvention.Cdecl)]
extern static void acdbEntUpd(Int64 e);
#endif

public static ResultBuffer GetResultBuffer(this ObjectId id)
{
Int64 e = new Int64();
IntPtr p = new IntPtr();
if (acdbGetAdsName(out e, id) == ErrorStatus.OK)
{
p = acdbEntGet(out e);
ResultBuffer rb = ResultBuffer.Create(p, true);
return rb;
}
else return null;
}

public static void ModifyDxfCodeValue(this ObjectId id, short code, object newTypeValue)
{
Int64 e = new Int64();
IntPtr p = new IntPtr();
if (acdbGetAdsName(out e, id) == ErrorStatus.OK)
{
p = acdbEntGet(out e);
ResultBuffer rb = ResultBuffer.Create(p, true);
EditorEx.WriteMessage(p.ToString());
ResultBufferEnumerator rbEnum = rb.GetEnumerator();
while (rbEnum.MoveNext())
{
if (rbEnum.Current.TypeCode == code)
{
//rbEnum.Current.Value = newTypeValue; <============ read only error here!

}
}
EditorEx.WriteMessage(rb.UnmanagedObject.ToString());
ResultBuffer rbMod = new ResultBuffer();
TypedValue[] temp = rb.AsArray();
foreach (TypedValue tp in temp)
{
TypedValue tpp = new TypedValue();
if (tp.TypeCode != code)
tpp = new TypedValue(tp.TypeCode, tp.Value);

else
tpp = new TypedValue(code, newTypeValue);
rbMod.Add(tpp);
}
//Interop.DetachUnmanagedObject(rb); 
//Interop.AttachUnmanagedObject(rbMod, p, true); <============not available error here!
acdbEntMod(p);
acdbEntUpd(e);
}
}

4 REPLIES 4
Message 2 of 5

As I understand you can not change ResultBuffer. Is that true?

//..........
ResultBuffer rb = ResultBuffer.Create(p, true);
TypedValue[] rbArr = rb.AsArray();
for (int i = 0; i < rbArr.Length; i++) {
  if (rbArr[i].TypeCode == code) {
    rbArr[i] = new TypedValue(code, newTypeValue);
  }
}
rb.Dispose();
rb = new ResultBuffer(rbArr);
//............

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 5

As Alex notes, you can't modify a ResultBuffer from managed code.

 

You should just work with an array of TypedValue[], and then

create a new ResultBuffer and pass the value of its UnmanagedObject

property to native code that requires a resbuf* pointer.

Message 4 of 5
275171906
in reply to: 275171906

is there anyway to use pointer(resultbuffer* ,eg) in managed code?

 

Message 5 of 5

Are you about this:

IntPtr p = IntPtr.Zero;
// p - pointer to first resbuf structure in resbuf list
// Creating managed ResultBuffer from unmanaged resbuf pointer ResultBuffer rb = ResultBuffer.Create(p, true);
// Now we can manipulate with managed rb
//.....................
// Getting unmanaged pointer to resbuf from managed ResultBuffer
p = rb.UnmanagedObject;

 ?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost